Remove unwanted parts from an image

6 vues (au cours des 30 derniers jours)
Guilherme Franklin
Guilherme Franklin le 28 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.

Réponse acceptée

Benjamin Thompson
Benjamin Thompson le 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
  1 commentaire
Guilherme Franklin
Guilherme Franklin le 30 Jan 2022
My friend, you saved me. Thank you very much, it really works perfectly.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by