Edge Detection and Transparency

Using images of garments made on a consistent basis, I would like to make all the pixels in the image transparent, with the exception of clothes. What is the best way to do this? I explored the algorithms that are common to this, and the opencv open source library. Besides the fact that I ride on my own or using opencv, is there an easy way to do this? I am open to any language or platform.

thanks

+6
image image-processing computer-vision edge-detection background-subtraction
source share
4 answers

If your background matches the image but is incompatible with the images, it can become complicated, but here is what I would do:

  • Separate the image in some form of intensity / color, such as YUV or Lab.
  • Make a histogram over the colored part. Find the most common color, this is (most likely) your background (update), perhaps the best trick here is to find the most common color of all pixels within one or two pixels from the edge of the image.
  • Starting from the image widget, set all the pixels that have this color and are connected to the edge through the pixels of that color until transparent.
  • The edge of the garment now looks a little ugly because it consists of pixels that take on color from both the background and the garment. To combat this, you need to do a little more work:

    1. Find the edge of the garment through the > gear .
    2. Replace the color of the edge pixels by mixing the color only "inside" the edge pixel (that is, the color of clothing in this region) and transparent (if it supports the output image format).
    3. If you want to get really fantasy, you will increase the transparency depending on how much the background color is like the color of this pixel.
+6
source share

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.

+2
source share

if you know the exact intensity of the background color and it will never change, and the garments will never match that color, then this is a simple application of subtracting the background, that is, anything that is not a specific color intensity is considered an “on” pixel of interest. You can then use the labeling of related components ( http://en.wikipedia.org/wiki/Connected_Component_Labeling ) to define individual groupings of objects.

0
source share

for a color image with the same background in each shot:

  • convert image to HSV or HSL
  • determine the value of the background hue (+/- 10): do this step once, using, for example, Photoshop, then use the same value in all your pictures.
  • fulfill the color threshold: on the hue channel, exclude the background hue (usually [0, hue [+] hue, 255]), for all other channels - the entire range of values ​​(usually from 0 to 255). this will select pixels that are NOT the background.
  • perform the “fill holes” operation (usually found from block analyzes or labeling functions) to fill in that part of the garment that may be the same color as the background.
  • now you have an image that is a “mask” of clothes: non-zero pixels represent clothes, 0 pixels represent a background.
  • This processing step depends on how you want the pixels to be transparent: usually, if you save your image as a PNG with alpha channel (transparency), use the logical AND operation (also called “masking”) between the alpha channel of the original image and masks in the previous step.
  • voilà, the background has disappeared, save the resulting image.
0
source share

All Articles