I have an image with red, green, blue channel and a binary version of the image.
What I want to do is concatenate those 2 images so that the binary image works as th
If you have a 3-D image I
and a binary mask M
, you can mask the irrelevant bits to zero either by multiplying the image by the mask:
I = bsxfun(@times, I, M);
or by logical indexing:
I(~mask(:, :, ones(1, size(I, 3)))) = 0;
You can use the binary image as a logical index in the 3dim image. To zero all pixels in image
that are zero in the binary mask
, you can use the following code for each dimension: image(~mask)=0;
I'm not 100% sure I understood your problem, but here goes one suggestion:
Suppose rgbIm
is your RGB image, and bwIm
is your binary image;
You may try to "expand" your binary image to "3D" (so that its dimensions are consistent with the original RGB image) with the following line of code:
bwImAux = bwIm(:,:,[1 1 1]);
And then perform a simple multiplication to "eliminate" all the pixels that are not ones in the binary image:
rgbImNew = rgbIm.*bwImAux;
Hope this helps.