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.

 Respuesta aceptada

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 comentarios

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 el 18 de Feb. de 2014
Editada: Animesh el 18 de Feb. de 2014
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 el 18 de Feb. de 2014
Editada: Image Analyst el 18 de Feb. de 2014
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.

Iniciar sesión para comentar.

Más respuestas (1)

Anagha
Anagha el 15 de Abr. de 2014
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 comentario

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.

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Feb. de 2014

Comentada:

el 15 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by