Masking an RGB Image with Binary Mask

前端 未结 1 433
礼貌的吻别
礼貌的吻别 2021-01-27 14:52

I have an RGB image (M x N x 3 matrix) in MATLAB that I read in. I also have a Binary mask (M x N matrix) for the image, which is simply 0 for some region of interest and 1 ever

相关标签:
1条回答
  • 2021-01-27 15:44

    You are misusing imfilter() there. Imfilter is used for linear filter operations, not for masking or thresholding. Better do this:

    z = image;          % image() is also a function. 
                        % Overwriting this name should be avoided
    
    % Request user polygon for ROI
    bw = roipoly(z);
    
    % Create 3 channel mask
    mask_three_chan = repmat(bw, [1, 1, 3]);
    
    % Apply Mask
    z(~mask_three_chan) = 0;
    
    % Display
    imshow(z);
    
    0 讨论(0)
提交回复
热议问题