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일
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

Why would you opt for HSV?? what difference does it makes?? please care to explain.
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).
Thanks a lot Sir,It works like a charm.
If I need to find the dominant color present in the image which is a better format RGB or HSV??
You can use either. More important is what your definition of "dominant" is.
Like in this image reddish-orange may be the dominant color..and like for a 50 rs note the dominant color maybe violet..
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

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 Exchange에서 Images에 대해 자세히 알아보기

태그

질문:

2014년 2월 14일

댓글:

2014년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by