3
$\begingroup$

I would like to segment picture of cloths in order to remove the background. The pictures come from online retailers, they usually have an homogeneous white background.

Using Canny edge detector works in most of the cases, but sometimes the cloths are nearly as white as the background making the edges hard to detect.

I tried to play with the min and max parameters in opencv (python), but I can't recover the clean edge, either I do not get the surrounding of the cloths (holes in the reigion) or the the edge is noisy around the cloth.

Here's one of the tricky example:

Original cloth Canny getting the contour of the cloth but noisy Canny not getting enough contour of the cloth

Simple growing region for background detection also doesn't work well enough.

So how do you detect the contour of an object if it has nearly the same color as the background?

$\endgroup$
  • $\begingroup$ the object is a texture with opacity? if so, just use Shobel with opacity as source value $\endgroup$ – Nadir Feb 25 at 19:23
  • $\begingroup$ Are many of these images the same? (Same camera angle) If the topology is roughly consistent it would be pretty easy to simply fill in the details on the latter image with some template. Wouldn't help much with the graphics on the tshirts though. $\endgroup$ – Andrew Wilson Feb 26 at 4:15
5
$\begingroup$

It's quite difficult. There is so little contrast, even the JPEG compression artifacts have more contrast than the object on the background.

You would require a highly specialized deblock filter to eliminate the compression artifacts first. With knowledge about the block size of the used compression algorithm and the number of coefficients used per block you may be able to predict some of the edges.

For edges you could predict in the previous step, you may try to filter these from the detected edges.


All around the shirt in the photo, there are over-swings due to an excessively lossy compression. At the edge of each block, the over-swings form a hard edge which you also successfully detected.

The block size is 8x8 pixels for JPEG (and hence also in this image), so every vertical or horizontal edge which falls directly onto position 8*n or 8n+1 X or Y is most likely just a compression artifact and can be ignored.

This approach can only work though if the image hasn't been re-sampled after compression, respectively hasn't been re-compressed multiple times with potentially different block sizes. At that point, isolating the compression artifacts becomes nearly impossible.

$\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.