Ask Your Question
0

Adding three images in opencv

asked 2013-04-26 08:04:51 -0600

Nermeen gravatar image

updated 2013-04-26 08:06:22 -0600

hi everybody i wanna ask if there is a way to add three images to gather (i wanna convert matlab code into opencv this is the statement in matlab:( greenObjectsMask = hueMask & saturationMask & valueMask;) )

the following is the code in opencv :

IplImage* hueMask = cvCreateImage( cvGetSize(h_plane), 8, 3 );
IplImage* saturationMask = cvCreateImage( cvGetSize(s_plane), 8, 3 );
IplImage* valueMask = cvCreateImage( cvGetSize(v_plane), 8, 3 );
IplImage* yellow = cvCreateImage( cvGetSize(v_plane), 8, 3 );
 cvThreshold( h_plane, h_plane,0.09*255,0.14*255,CV_THRESH_BINARY);
 cvThreshold( s_plane, s_plane,0.1*255,1.0*255,CV_THRESH_BINARY);
 cvThreshold( v_plane, v_plane,0.1*255,1.0*255,CV_THRESH_BINARY);
 cvShowImage("h mask ",h_plane );
 cvShowImage("s mask ",s_plane );
 cvShowImage("v mask ",v_plane );

i wanna to add the huemask, saturationmask and valuemask in one image called greenObjectsMask waiting for help thank u all

edit retag flag offensive close merge delete

Comments

As far as i know greenObjectsMask = hueMask & saturationMask & valueMask; is more bitwise_and than add in matlab

Rogeeeer gravatar imageRogeeeer ( 2013-04-26 08:26:26 -0600 )edit

i tried to use bitwise function but it doesn't work

Nermeen gravatar imageNermeen ( 2013-04-26 09:25:41 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-04-26 08:29:44 -0600

Actually I am guessing he wants a 3 channel image, but combined into a single matrix. This can be done the following way:

Mat 3channels(hueMask.rows, hueMask.cols, CV_8UC3);
Mat in[] = { hueMask , saturationMask, valueMask };
int from_to[] = { 0,0, 1,1, 2,2 };
mixChannels( in, 3, &3channels, 1, from_to, 3 );
edit flag offensive delete link more

Comments

thank you a lot. as i said I'm new in opencv i want the three images (huemask ,saturation mask and value mask) to be one image .in this case should i use cvmerge or mixchannels?

Nermeen gravatar imageNermeen ( 2013-04-26 09:07:45 -0600 )edit

If you want a single channel image, then merge would be the way to go. But if I read your other posts, you basically have three masks of 1 and 0 values, three binary matrices. Just use the

 Mat temp = mat1.mul(mat2);
 Mat result = temp.mul(mat3);

this should work, have done it multiple times already in own code

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-26 10:10:22 -0600 )edit
0

answered 2013-04-26 08:20:29 -0600

berak gravatar image

i think, you want cvMerge(hueMask, saturationMask,valueMask, 0, greenObjectsMask);

your code is a bit messy/unclear there, the masks you want to merge, are all empty, is that intended ?

and you probably want

cvCreateImage( cvGetSize(h_plane), 8, 1 );

instead of

cvCreateImage( cvGetSize(h_plane), 8, 3 );

( the mask needs 1 chan only, right ? )

also, why again are you using the old 1.0 api ?

edit flag offensive delete link more

Comments

actually I'm new in opencv and c++ i started using it since 2 days only. about using old api my supervisor advised me to use opencv 2.2.0 with visual studio 2006 and i did. hope that was a good answer. i really need help and i wish if u can help me. can i paste my full code here to tell whats the matter?

Nermeen gravatar imageNermeen ( 2013-04-26 09:01:31 -0600 )edit

for sure thank u for ur appreciation

Nermeen gravatar imageNermeen ( 2013-04-26 09:02:36 -0600 )edit

Question Tools

Stats

Asked: 2013-04-26 08:04:51 -0600

Seen: 772 times

Last updated: Apr 26 '13