Remove unwanted parts from an image
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Benjamin Thompson
2022-1-28
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!