Matlab - How to mask a 3-D image using a binary image

后端 未结 3 1819
感动是毒
感动是毒 2020-12-20 06:21

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

相关标签:
3条回答
  • 2020-12-20 06:54

    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;
    
    0 讨论(0)
  • 2020-12-20 06:55

    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;

    0 讨论(0)
  • 2020-12-20 07:15

    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.

    0 讨论(0)
提交回复
热议问题