Clear Filters
Clear Filters

Remove the unwanted region from an image....

1 view (last 30 days)
Piyum Rangana
Piyum Rangana on 26 Mar 2017
Commented: Image Analyst on 27 Mar 2017
I have image with an unwanted area, and I want to remove that area and make a mask(RGB) after that operation. How can I easily do this task ? Note : I have attached an image file in which I need to remove the degraded area from that and create a mask. Thankz

Answers (1)

Image Analyst
Image Analyst on 26 Mar 2017
To make a mask you can just see where each color channel is bright. That will detect the white areas and make a mask.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get a mask of "white" where red, green, and blue are all high at the same location.
mask = redChannel > 240 & greenChannel > 240 & blueChannel > 240;
I don't know what "remove" means. You can't remove it since images must remain rectangular. If you want to "fill" it, you can use regionfill(), passing it the original RGB image and the mask, or you can "crop" it out to another smaller rectangular region. So please give your definition of "remove".
  2 Comments
Piyum Rangana
Piyum Rangana on 26 Mar 2017
Edited: Piyum Rangana on 26 Mar 2017
Thanks for the answer. What I meant from 'Remove' is ignore those pixels and I need to inpaint that area further. How ever I tried with the code and below line
mask = redChannel > 240 & greenChannel > 240 & blueChannel > 240;
not worked for me. I print the 'mask' and the pixel values all get zeros. how can I fix that ?
Image Analyst
Image Analyst on 27 Mar 2017
Sorry, I assumed that you would know to change the 240 value to whatever works. I guessed wrong. So I used the Color Thresholder (on the Apps tab) to determine the "white" for your pixture and this is what I came up with:
mask = redChannel > 206 & greenChannel > 153 & blueChannel > 114;
If you can't finish it now, then let me know.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!