Remove Background from image and select the region of interest

I have a image
and I want to remove the background and select the region of interest and my output should be
How can I do it ? thanks in advance.

 採用された回答

Image Analyst
Image Analyst 2014 年 2 月 14 日

2 投票

For this image, the background is neutral and the subject is not. So I'd probably convert to hsv with rgb2hsv() and then threshold on saturation to get highly saturated pixels. The background won't get selected. Then get rid of any small regions with bwareaopen, call regionprops, get the bounding box, and call imcrop(). The essential lines are few:
hsv=rgb2hsv(rgbImage);
s = hsv(:,:,2);
foreground = s > 0.2; % Or whatever.
foreground = bwareaopen(foreground, 1000); % or whatever.
labeledImage = bwlabel(foreground);
measurements = regionprops(labeledImage, 'BoundingBox');
bb = measurements.BoundingBox;
croppedImage = imcrop(rgbImage, bb);
or something like that. I didn't test it - that's just off the top of my head.

9 件のコメント

Dishant Arora
Dishant Arora 2014 年 2 月 14 日
Why would you opt for HSV?? what difference does it makes?? please care to explain.
Image Analyst
Image Analyst 2014 年 2 月 14 日
Because it's way easier than RGB. The problem is the background varies from dark (low RGB values) to bright (high RGB values), so if you were to try to threshold it, you'd have to change your threshold for every pixel in the image. But since we know the background is neutral colored (r=g=b) no matter if it's dark or bright, then we can threshold the saturation image with only a single threshold. You might be able to do it for this particular image in RGB with some special complicated operations but then those won't work if you image a blue note, or a green note instead of this peach colored note. If you look at saturation, it does not care what color the note is. It only cares if it has color (any color at all) or is neutral (black, gray, white).
Animesh
Animesh 2014 年 2 月 14 日
Thanks a lot Sir,It works like a charm.
Animesh
Animesh 2014 年 2 月 17 日
If I need to find the dominant color present in the image which is a better format RGB or HSV??
Image Analyst
Image Analyst 2014 年 2 月 17 日
You can use either. More important is what your definition of "dominant" is.
Animesh
Animesh 2014 年 2 月 18 日
Like in this image reddish-orange may be the dominant color..and like for a 50 rs note the dominant color maybe violet..
Image Analyst
Image Analyst 2014 年 2 月 18 日
You need a mathematical definition. Do you mean the mode, mean, or centroid? What if you have two clusters: a smaller white cluster, and a larger red cluster? What's the dominant color? Pink (somewhere between the two clusters)? Red (because there's more of them)? Maybe to answer that, you first need to clarify what you'd do with that info if you had it.
Animesh
Animesh 2014 年 2 月 18 日
編集済み: Animesh 2014 年 2 月 18 日
I am trying to find the denomination of the note by using two features
1)Dominant color
2)Ratio of length/width.
And for the above I would take the dominant color as there are more of them.
Image Analyst
Image Analyst 2014 年 2 月 18 日
編集済み: Image Analyst 2014 年 2 月 18 日
Sounds like just taking the mean color would be good enough to tell which note it is. I don't see any need to do anything fancier or more difficult.

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

その他の回答 (1 件)

Anagha
Anagha 2014 年 4 月 15 日

0 投票

Hello,
I'm also facing similar problem. I want to crop the egg image from black background for further image processing. I'm attaching the image. Please help me in this regard. Really urgent!!

1 件のコメント

Image Analyst
Image Analyst 2014 年 4 月 15 日
Please start your own thread. Post your image there and explain why you want to crop. Cropping is not necessary for analysis, so why do you want to crop? Answer in your own, new thread, not here.

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

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by