边缘检测和透明度

发布于 2024-08-08 22:08:45 字数 213 浏览 11 评论 0 原文

使用在一致背景下拍摄的服装图像,我希望使图像中除服装之外的所有像素都透明。解决这个问题的最佳方法是什么?我研究了常见的算法和开源库 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蓝天 2024-08-15 22:08:45

如果您的背景在图像中一致,但图像之间不一致,则可能会变得棘手,但我会这样做:

  1. 将图像分离为某种强度/颜色形式,例如 YUV 或 Lab。
  2. 在颜色部分上制作直方图。找到最常出现的颜色,这(最有可能)是您的背景(更新),也许这里更好的技巧是找到距离图像边缘一两个像素内的所有像素中最常出现的颜色。
  3. 从图像的边缘开始,将具有该颜色并通过该颜色的像素连接到边缘的所有像素设置为透明。
  4. 这件衣服的边缘现在看起来有点难看,因为它由从背景和这件衣服获得颜色的像素组成。为了解决这个问题,你需要做更多的工作:

  5. 通过某种边缘检测机制找到衣服的边缘。
  6. 将边缘像素的颜色替换为边缘像素“内部”的颜色(即该区域的衣服颜色)和透明颜色(如果您的输出图像格式支持)的混合颜色。
  7. 如果您想变得非常奇特,您可以根据该像素的颜色与背景颜色的“相似程度”来增加透明度。

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.
盛夏尉蓝 2024-08-15 22:08:45

基本上,找到背景的颜色并减去它,但我想你知道这一点。自动完成这一切有点棘手,但似乎是可能的。

首先,看一下使用 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.

草莓味的萝莉 2024-08-15 22:08:45

如果您知道背景的确切颜色强度,并且它永远不会改变,并且服装永远不会与该颜色一致,那么这是背景减法的简单应用,也就是说,所有不是特定颜色强度的东西都被认为是“在”像素上,感兴趣的之一。然后,您可以使用连接组件标签 (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.

能怎样 2024-08-15 22:08:45

对于彩色图像,每张图片都具有相同的背景:

  • 将图像转换为 HSV 或 HSL
  • 确定背景的色调值 (+/-10):执行此步骤一次,例如使用 Photoshop,然后在你所有的照片。
  • 执行颜色阈值:在色调通道上排除背景的色调(通常为 [0,hue[ + ]hue, 255]),因为所有其他通道包括整个值范围(通常为 0 到 255)。这将选择不是背景的像素。
  • 执行“填充孔”操作(通常在斑点分析或标记功能中发现)以完成可能与背景颜色相同的衣服部分。
  • 现在你有一个图像,它是衣服的“面具”:非零像素代表衣服,0 像素代表背景。
  • 此处理步骤取决于您希望如何使像素透明:通常,如果您将图像保存为带有 alpha(透明)通道的 PNG,请在 alpha 通道之间使用逻辑 AND(也称为“遮罩”)运算。原始图像和上一步中构建的掩模。
  • 瞧,背景消失了,保存生成的图像。

for a color image, with the same background on every pictures:

  • convert your image to HSV or HSL
  • determine the Hue value of the background (+/-10): do this step once, using photoshop for example, then use the same value on all your pictures.
  • perform a color threshold: on the hue channel exclude the hue of the background ([0,hue[ + ]hue, 255] typically), for all other channels include the whole value range (0 to 255 typically). this will select pixels which are NOT the background.
  • perform a "fill holes" operation (normally found along blob analysis or labelling functions) to complete the part of the clothes which may have been of the same color than the background.
  • now you have an image which is a "mask" of the clothes: non-zero pixels represents the clothes, 0 pixels represents the background.
  • this step of the processing depends on how you want to make pixels transparent: typically, if you save your image as PNG with an alpha (transparency) channel, use a logical AND (also called "masking") operation between the alpha channel of the original image and the mask build in the previous step.
  • voilà, the background disappeared, save the resulting image.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文