Search code examples
imageimage-processingcomputer-visionedge-detectionbackground-subtraction

Edge Detection and transparency


Using images of articles of clothing taken against a consistent background, I would like to make all pixels in the image transparent except for the clothing. What is the best way to go about this? I have researched the algorithms that are common for this and the open source library opencv. Aside from rolling my own or using opencv is there an easy way to do this? I am open to any language or platform.

Thanks


Solution

  • If your background is consistend in an image but inconsistent across images it could get tricky, but here is what I would do:

    1. Separate the image into some intensity/colour form such as YUV or Lab.
    2. Make a histogram over the colour part. Find the most occuring colour, this is (most likely) your background (update) maybe a better trick here would be to find the most occuring colour of all pixels within one or two pixels from the edge of the image.
    3. Starting from the eddges of the image, set all pixels that have that colour and are connected to the edge through pixels of that colour to transparent.
    4. The edge of the piece of clothing is now going to look a bit ugly because it consist of pixels that gain their colour from both the background and the piece of clothing. To combat this you need to do a bit more work:

      1. Find the edge of the piece of clothing through some edge detection mechanism.
      2. Replace the colour of the edge pixels with a blend of the colour just "inside" the edge pixel (i.e. the colour of the clothing in that region) and transparent (if your output image format supports that).
      3. If you want to get really fancy, you increase the transparency depending on how much "like" the background colour the colour of that pixel is.