0
$\begingroup$

Suppose that I have an image with a foreground subject and a monochrome background. The image is a real world picture so the pixels belonging to the background do not share the same exact value. I want to isolate the foreground but I don't know the background color in advance. What are the state of the art algorithms to achieve this goal?

$\endgroup$
1
$\begingroup$

Something self-written should be easy. "Background" probably means that the majority of pixels at the border of your image have that color.

So, just get all the border pixels, put them in an array, convert to hue and then do a histogram. Use the maximum histogram bin as your chroma key color.

  • Starting with border pixels of that color, erode your image on a hue gradient, i.e. make sure that the hue doesn't change too much from its neighboring pixels, and then add pixels to your background mask until you're done OR
  • just do classical chroma-keying and convert all pixels of colors "close enough" to that color to background mask.
$\endgroup$
  • $\begingroup$ Thank you, it seems a good idea. Can you explain me the first point (erode on a hue gradient)? I know what image erosion is but I didn't get how to use it in this case. $\endgroup$ – firion Jan 9 at 7:13
  • $\begingroup$ you take a pixel you know is part of the mask (i.e. your starting point border pixel). You look at its neighbors: are they close enough in hue so that they are background, too? If yes, add to the list of pixels in the mask and look at their neighbors later. $\endgroup$ – Marcus Müller Jan 9 at 9:57
1
$\begingroup$

Use kmeans clustering center the maximum cluster u get is the background color

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.