Basically, find the background color and subtract it, but I think you knew that. It is a little difficult to do it automatically, but it seems possible.
First take a look at blob detection with OpenCV and see if this is really done for you.
To do it yourself:
find the background . There are several options. Probably the easiest way is the histogram of the image, and a large number of pixels with similar values - the background, and if there are two large collections, then the background will be the one with a large hole in the middle. Another approach is to take the strip around the perimeter as the background color, but it seems worse, for example, reflection from the flash can significantly brighten more centrally located background pixels.
remove the background : first take the threshold value of the image based on the background color, then run the “open” or “closed” algorithms on it, and then use it as a mask to select your clothes. (The opening / closing point is to not remove small background colored objects on clothes, like black buttons on a white blouse or, say, bright reflections on black clothes.)
OpenCV is a good tool for this.
The hardest part of this will probably be in the shadow around the object (for example, a black jacket on a white background will have a continuous gray shadow at some edges and where to do it?), But if you get this one more question.
tom10
source share