Remove unwanted parts from an image

6 ビュー (過去 30 日間)
Guilherme Franklin
Guilherme Franklin 2022 年 1 月 28 日
コメント済み: Guilherme Franklin 2022 年 1 月 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.

採用された回答

Benjamin Thompson
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
  1 件のコメント
Guilherme Franklin
Guilherme Franklin 2022 年 1 月 30 日
My friend, you saved me. Thank you very much, it really works perfectly.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by