如何删除背景图像并获得前景图像

发布于 2024-08-18 10:42:08 字数 543 浏览 6 评论 0原文

有两张图片

alt text http://bbs.shoucangshidai.com/attachments/month_1001/1001211535bd7a644e95187acd.jpg 替代文本http://bbs.shoucangshidai.com/attachments/month_1001/10012115357cfe13c148d3d8da.jpg 一张是背景图像,另一张是具有相同背景、相同尺寸的人的照片,我想要做的是删除第二张图像的背景并仅提取该人的个人资料。常见的方法是从第二张图像中减去第一张图像,但我的问题是人的穿着颜色是否与背景相似。减法的结果很糟糕。我无法获得整个人的个人资料。谁有去除背景的好主意给我一些建议。 先感谢您。

there are two images

alt text http://bbs.shoucangshidai.com/attachments/month_1001/1001211535bd7a644e95187acd.jpg
alt text http://bbs.shoucangshidai.com/attachments/month_1001/10012115357cfe13c148d3d8da.jpg
one is background image another one is a person's photo with the same background ,same size,what i want to do is remove the second image's background and distill the person's profile only. the common method is subtract first image from the second one,but my problem is if the color of person's wear is similar to the background. the result of subtract is awful. i can not get whole people's profile. who have good idea to remove the background give me some advice.
thank you in advance.

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

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

发布评论

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

评论(6

暮年 2024-08-25 10:42:08

如果您对图像背景有很好的估计,那么从人物图像中减去它是一个很好的第一步。但这只是第一步。之后,您必须对图像进行分割,即必须将图像划分为“背景”和“前景”像素,并具有如下约束:

  1. 在前景区域中,与背景图像的平均差异应该
  2. 在背景中 较高与背景图像的平均差异应该较低的
  3. 区域应该是平滑的。轮廓长度和曲率应该最小。
  4. 区域的边界在源图像中应具有高对比度

如果您有数学倾向,则可以使用 Mumford-Shah 函数完美地对这些约束进行建模。 请参阅此处了解更多信息。

但是您可能可以调整其他细分问题的算法。

如果您想要一个快速且简单(但不完美)的版本,您可以尝试以下操作:

  • 将两个图像相减
  • ,找到背景-前景差异大于某个阈值的最大连续像素“斑点”。这是对前景图像中“人物区域”的第一次粗略估计,但是分割不满足上面的标准3和4。
  • 找到最大斑点的轮廓(编辑:请注意,您不必从轮廓开始。您也可以从较大的多边形开始,因为步骤会自动将其缩小到最佳位置.)
  • 现在检查轮廓中的每个点并平滑轮廓。即对于每个点,找到使公式 c1*L - c2*G 最小化的点,其中 L 是点移动到此处时轮廓多边形的长度,G 是点将移动到的位置处的梯度, c1/c2 是控制过程的常数。将点移动到该位置。这具有平滑源图像中低梯度区域中的轮廓多边形的效果,同时保持其与源图像中的高梯度(即人的可见边界)相关。您可以尝试不同的 L 和 G 表达式,例如,L 可以考虑长度和曲率,G 还可以考虑背景和减影图像中的梯度。
  • 您可能必须重新规范化轮廓多边形,即确保轮廓上的点间隔规则。或者,或者确保在之前的步骤中点之间的距离保持规则。 (“测地线蛇”)
  • 重复最后两个步骤直到收敛

您现在有一个轮廓多边形,它接触可见的人物背景边界,并在边界不可见或对比度较低的地方平滑地继续。
查找“Snakes”(例如此处)了解更多信息。

If you have a good estimate of the image background, subtracting it from the image with the person is a good first step. But it is only the first step. After that, you have to segment the image, i.e. you have to partition the image into "background" and "foreground" pixels, with constraints like these:

  1. in the foreground areas, the average difference from the background image should be high
  2. in the background areas, the average difference from the background image should be low
  3. the areas should be smooth. Outline length and curvature should be minimal.
  4. the borders of the areas should have a high contrast in the source image

If you are mathematically inclined, these constraints can be modeled perfectly with the Mumford-Shah functional. See here for more information.

But you can probably adapt other segmentation algorithms to the problem.

If you want a fast and simple (but not perfect) version, you could try this:

  • subtract the two images
  • find the largest consecutive "blob" of pixels with a background-foreground difference greater than some threshold. This is the first rough estimate for the "person area" in the foreground image, but the segmentation does not meet the criteria 3 and 4 above.
  • Find the outline of the largest blob (EDIT: Note that you don't have to start at the outline. You can also start with a larger polygon, as the steps will automatically shrink it to the optimal position.)
  • now go through each point in the outline and smooth the outline. i.e. for each point find the point that minimizes the formula: c1*L - c2*G, where L is the length of the outline polygon if the point were moved here and G is the gradient at the location the point would be moved to, c1/c2 are constants to control the process. Move the point to that position. This has the effect of smoothing the contour polygon in areas of low gradient in the source image, while keeping it tied to high gradients in the source image (i.e. the visible borders of the person). You can try different expressions for L and G, for example, L could take the length and curvature into account, and G could also take the gradient in the background and subtracted images into account.
  • you probably will have to re-normalize the outline polygon, i.e. make sure that the points on the outline are spaced regularly. Either that, or make sure that the distances between the points stay regular in the step before. ("Geodesic Snakes")
  • repeat the last two steps until convergence

You now have an outline polygon that touches the visible person-background border and continues smoothly where the border is not visible or has low contrast.
Look up "Snakes" (e.g. here) for more information.

笨死的猪 2024-08-25 10:42:08

在减去图像之前对图像进行低通滤波(模糊)。
然后使用该差异信号作为掩模来选择感兴趣的像素。
足够宽的滤波器将忽略太小的(高频)特征,这些特征最终会在您感兴趣的对象内雕刻出“可怕”的区域。它还会减少像素级噪声和未对准(最高频率信息)的突出显示。

此外,如果您有两个以上的帧,引入一些时间滞后也可以让您随着时间的推移形成更稳定的感兴趣区域。

Low-pass filter (blur) the images before you subtract them.
Then use that difference signal as a mask to select the pixels of interest.
A wide-enough filter will ignore the too-small (high-frequency) features that end up carving out "awful" regions inside your object of interest. It'll also reduce the highlighting of pixel-level noise and misalignment (the highest-frequency information).

In addition, if you have more than two frames, introducing some time hysteresis will let you form more stable regions of interest over time too.

明月夜 2024-08-25 10:42:08

我认为常见的一种技术是使用混合模型。获取多个背景帧,并为每个像素为其颜色构建一个混合模型。

当您应用其中包含人物的帧时,根据每个像素的混合模型中的概率密度,您将获得该颜色是前景或背景的一定概率。

在获得 P(像素是前景)和 P(像素是背景)之后,您可以对概率图像进行阈值处理。

另一种可能性是使用概率作为一些更聪明的分割算法的输入。一个例子是 图形切割,我注意到它效果很好。

然而,如果该人穿着在视觉上与背景难以区分的衣服,显然上述方法都不起作用。你要么必须获得另一个传感器(如红外线或紫外线),要么拥有一个非常复杂的“人物模型”,如果它发现它认为是躯干和头部,它可以将腿“添加”到正确的位置。

祝项目顺利!

One technique that I think is common is to use a mixture model. Grab a number of background frames and for each pixel build a mixture model for its color.

When you apply a frame with the person in it you will get some probability that the color is foreground or background, given the probability densities in the mixture model for each pixel.

After you have P(pixel is foreground) and P(pixel is background) you could just threshold the probability images.

Another possibility is to use the probabilities as inputs in some more clever segmentation algorithm. One example is graph cuts which I have noticed works quite well.

However, if the person is wearing clothes that are visually indistguishable from the background obviously none of the methods described above would work. You'd either have to get another sensor (like IR or UV) or have a quite elaborate "person model" which could "add" the legs in the right position if it finds what it thinks is a torso and head.

Good luck with the project!

扛起拖把扫天下 2024-08-25 10:42:08

背景与前景检测是非常主观的。应用场景定义背景或前景。然而,在您详细介绍的应用程序中,我猜您隐含地说该人是前景。
使用上述假设,您寻求的是人员检测算法。一个可能的解决方案是:

  1. 运行 haar 特征检测器+弱分类器的增强级联
    (有关详细信息,请参阅 opencv wiki
  2. 计算帧间运动(差异)
  3. 如果某帧有 +ve 人脸检测,则对运动像素进行聚类
    脸部周围(kNN 算法

瞧……你应该有一个简单的人物检测器。

Background vs Foreground detection is very subjective. The application scenario defines background or foreground. However in the application you detail, I guess you are implicitly saying that the person is the foreground.
Using the above assumption, what you seek is a person detection algorithm. A possible solution is:

  1. Run a haar feature detector+ boosted cascade of weak classifiers
    (see the opencv wiki for details)
  2. Compute inter-frame motion (differences)
  3. If there is a +ve face detection for a frame, cluster motion pixels
    around the face (kNN algorithm)

voila... you should have a simple person detector.

陌若浮生 2024-08-25 10:42:08

您可以逐个像素地遍历两个图像,而不是直接进行减法,并且仅“减去”完全相同的像素。但这当然不能解释颜色的微小差异。

Instead of a straight subtraction, you could step through both images, pixel by pixel, and only "subtract" the pixels which are exactly the same. That of course won't account for minor variances in colors, though.

怪我鬧 2024-08-25 10:42:08

将照片发布到 Craigslist 上,并告诉他们您将支付 5 美元请人拍摄。

保证您会在几分钟内获得点击。

Post the photo on Craigslist and tell them that you'll pay $5 for someone to do it.

Guaranteed you'll get hits in minutes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文