First time here? Check out the FAQ!

Ask Your Question
0

Adding three images in opencv

asked Apr 26 '13

Nermeen gravatar image

updated Apr 26 '13

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

Preview: (hide)

Comments

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

Rogeeeer gravatar imageRogeeeer (Apr 26 '13)edit

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

Nermeen gravatar imageNermeen (Apr 26 '13)edit

2 answers

Sort by » oldest newest most voted
0

answered Apr 26 '13

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 );
Preview: (hide)

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 (Apr 26 '13)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 (Apr 26 '13)edit
0

answered Apr 26 '13

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 ?

Preview: (hide)

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 (Apr 26 '13)edit

for sure thank u for ur appreciation

Nermeen gravatar imageNermeen (Apr 26 '13)edit

Question Tools

Stats

Asked: Apr 26 '13

Seen: 797 times

Last updated: Apr 26 '13