使用在一致背景下拍摄的服装图像,我希望使图像中除服装之外的所有像素都透明。解决这个问题的最佳方法是什么?我研究了常见的算法和开源库 opencv。除了自己动手或使用 opencv 之外,还有一种简单的方法可以做到这一点吗?我对任何语言或平台都持开放态度。
谢谢
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
发布评论
评论(4)
如果您的背景在图像中一致,但图像之间不一致,则可能会变得棘手,但我会这样做:
这件衣服的边缘现在看起来有点难看,因为它由从背景和这件衣服获得颜色的像素组成。为了解决这个问题,你需要做更多的工作:
If your background is consistend in an image but inconsistent across images it could get tricky, but here is what I would do:
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:
基本上,找到背景的颜色并减去它,但我想你知道这一点。自动完成这一切有点棘手,但似乎是可能的。
首先,看一下使用 OpenCV 进行斑点检测,看看这是否基本上已经为您完成。
自己动手:
查找背景:有多种选择。最简单的可能是对图像进行直方图,大量具有相似值的像素就是背景,如果有两个大集合,则背景将是中间有一个大洞的那个。另一种方法是采用周边的带作为背景颜色,但这似乎较差,因为例如来自闪光灯的反射可能会显着地使位于中心的背景像素变亮。
删除背景:首先是根据背景颜色对图像进行阈值处理,然后对其运行“打开”或“关闭”算法,然后将其用作遮罩选择您的服装物品。 (打开/关闭的目的是不要删除衣服上的小背景颜色项目,例如白色衬衫上的黑色纽扣,或者黑色衣服上的明亮反射。)
OpenCV 是一个很好的工具。
其中最棘手的部分可能是物体周围的阴影(例如,白色背景上的黑色夹克在某些边缘处会有连续的灰色阴影,在哪里进行此切割?),但如果你走到这一步,发布另一个问题。
Basically, find the color of the background and subtract it, but I guess you knew this. It's a little tricky to do this all automatically, but it seems possible.
First, take a look at blob detection with OpenCV and see if this is basically done for you.
To do it yourself:
find the background: There are several options. Probably easiest is to histogram the image, and the large number of pixels with similar values are the background, and if there are two large collections, the background will be the one with a big hole in the middle. Another approach is to take a band around the perimeter as the background color, but this seems inferior as, for example, reflection from a flash could dramatically brighten more centrally located background pixels.
remove the background: a first take at this would be to threshold the image based on the background color, and then run the "open" or "close" algorithms on this, and then use this as a mask to select your clothing article. (The point of open/close is to not remove small background colored items on the clothing, like black buttons on a white blouse, or, say, bright reflections on black clothing.)
OpenCV is a good tool for this.
The trickiest part of this will probably be at the shadow around the object (e.g. a black jacket on a white background will have a continuous gray shadow at some of the edges and where to make this cut?), but if you get this far, post another question.
如果您知道背景的确切颜色强度,并且它永远不会改变,并且服装永远不会与该颜色一致,那么这是背景减法的简单应用,也就是说,所有不是特定颜色强度的东西都被认为是“在”像素上,感兴趣的之一。然后,您可以使用连接组件标签 (http://en.wikipedia.org/wiki/Connected_Component_Labeling) 找出对象的单独分组。
if you know the exact color intensity of the background and it will never change and the articles of clothing will never coincide with this color, then this is a simple application of background subtraction, that is everything that is not a particular color intensity is considered an "on" pixel, one of interest. You can then use connected component labeling (http://en.wikipedia.org/wiki/Connected_Component_Labeling) to figure out seperate groupings of objects.
对于彩色图像,每张图片都具有相同的背景:
for a color image, with the same background on every pictures: