Remove unwanted parts from an image
6 views (last 30 days)
Show older comments
Guilherme Franklin
on 28 Jan 2022
Commented: Guilherme Franklin
on 30 Jan 2022
I'm working with image processing and would like to develop an algorithm capable of automatically removing unwanted parts from an image.
An example image below:
I want to leave only the white background with the leaves and I want to remove the sides.
PS: I'm using a bank of images that are different, they all have a white background with the leaves, but they don't have the same borders.
0 Comments
Accepted Answer
Benjamin Thompson
on 28 Jan 2022
colorThresholder seems to do pretty well using the LAB color space. I generated the attached mask function using colorThresholder. Then use regionprops to get a bounding box around the white pixels. If you can ensure there is some white around all leaves first it gets a lot easier. You may want to use labeling functions like bwconncomp to find small outlying regions of white pixels to discard. Then if you can get one bounding box that includes all the white area including leaves, you can copy that portion of the image into a smaller image or just set all the pixels outside the bounding box to black.
See imfill and other "Morphological Operations" in order to try to do things like replace small holes in a mask.
A = imread('leafImage.jpeg');
maskA = createMaskWhiteBackground(A);
s = regionprops(maskA,'BoundingBox');
>> bb = s.BoundingBox
bb =
1.0e+03 *
0.6225 6.5175 0.0020 0.0050
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!