从照片中减去图像背景 [英] Subtract Image background from photo

查看:95
本文介绍了从照片中减去图像背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在开发一种用户可以从照片中减去背景的软件。照片可能是任何人或团体照片。

我成功地从照片中删除了背景。

我的问题是:

我的逻辑能够将人与照片区分开来。但在输出图像中,人物边界正在被像素化。并且人物边框呈现白色。

更多理解请查看图片链接。

请建议我如何清楚地提取边框。





http://i55.tinypic.com/ zn4wmd.jpg [ ^ ]

推荐答案

我可以给你一个简单的想法:这很难,几乎不可能。



我可以说,因为我有很长的使用照片编辑的经验,使用不同的软件,包括最好的产品。很多人对背景去除/更换功能印象深刻。但我从未留下深刻的印象,因为经验丰富的眼睛总能看到边缘的那些问题。请注意,该软件采用了日志方式来更好地解决这个问题,但结果并不令人印象深刻。顺便说一句,这种方法似乎保密。如果你看一下开源GIMP(实现了像治疗刷这样最智能的算法),就没有这样的东西了。好吧,不是一个认真的摄影师。



我也试图解决类似的问题。我的解决方案有效,并且比其他工具有一些好处,但我仍然没有热情 - 完全没有。



我可以告诉你原因。留出繁忙的背景之前或之后。想象一下,你有绿色背景(在电影院,他们经常使用蓝屏或绿屏),想用红色代替它(黑色或透明只是难以解释,但结论将是相同的)。在照片上,这意味着你的头部有头发和皮肤。问题不在于轮廓(严格来说,没有轮廓 - 惊喜!)。问题在于每根单根头发,在每个皮肤毛孔上都有一个模糊的绿色高光,每个都有各自的大小和亮度,取决于方向和其他因素,亮点与个别材料颜色和来自其他来源的光混合,而不仅仅是从这个绿色背景反射的光。此效果始终可见。所以,问题是模仿不同颜色的所有亮点。但是,从背景和其他光源反射的光的分离已经是一个困难的图像识别问题。使用非常简单的遮罩物体伪造要容易得多,但即使这样也很困难。通常情况下,我可以从第一眼看到伪造品。



我不说我从未见过伪造的图像。是的,我做到了;有些作品很棒,但我所知道的只是真正大师的手工工艺品,每件作品花费数小时,数周或数月。



只有便宜的低分辨率原版图片可以产生非常大致匹配原始质量的结果。非常常见的廉价技巧是在轮廓周围的模糊区域(模糊区域非常重要)上应用一些高斯模糊。如果您需要质量非常差的图像,您可以实现它,但即使这样也不容易,并且在100%的情况下不能自动完成。只需看看你发布的图片。谁会有这样的厌恶?



所以,你可以得到一些解决方案,但我不相信质量值得付出努力。当然,这只是我的观点,但我会帮助您了解问题。



对不起,

-SA
PS :我可以想象这篇文章引起的愤怒,以及下选票。欢迎你!

然而,在我看来,我会急切希望看到任何可能引起怀疑的事情。现在我认为我可以在通过自动图像处理创建的每个图像上发现伪造。如果有人能证明不是这样,我会非常兴奋。有什么建议吗?
I can give you a simple idea: this is very difficult, nearly impossible.

I can tell, because I have a very long experience working with photo editing, using different software, including very best products. Many people are very impressed with background removal/replacement feature. But I was never impressed, because experienced eye always see those problems around the edge. Mind it, the software went a log way to solve this problem better and better, but results are not impressive at all. By the way, the method are seemingly kept in secret. If you look at Open Source GIMP (where the most intellectual algorithm like "Healing Brush" are implemented), there is not such thing. Well, not for a serious photographer.

I also tried to solve similar problems. My solution worked and had some benefits over other tools, but I'm still not enthusiastic — not at all.

I can give you idea why. Set aside busy background "before" or "after". Imagine you have green background (in cinema, they routinely used "blue screen" or "green screen"), want to replace it with red (black or transparent is just harder to explain, but the conclusion will be the same). On a photograph, it means that you have a human head with hair and skin. The problem is not about contour (strictly speaking, there is no contour — surprise!). The problem is that on every single hair, on every pore of the skin you have a fuzzy green highlights, each one at its individual size and brightness, depending and on orientation and other factors, the highlights is blended with individual material color and light from other sources, not just from light reflected from this green background. This effect is always visible. So, the problem is to imitate all those highlights in different color. But separation of the light reflected from background and other sources is already a difficult image recognition problem. It's much easier to fake with very simple matte objects, but even this is very difficult. Usually, I can spot the forgery from a first glance.

I don't say I never saw good forged images. Yes I did; some works are amazing, but all I knew were manual crafts of real masters who spend hours, weeks or months on each work.

Only a cheap, low-resolution original picture can yield the result very roughly matching the quality of the original. Very common cheap trick is to apply some Gaussian blur on a fuzzy area (fuzzy region is critically important) around the contour. If you need a very poor quality image, you can achieve it, but even this is not easy and not working out automatically in 100% of cases. Just look at the picture you posted. Who would ever need such disgust?

So, you can get some solution, but I cannot believe the quality could worth the effort. Of course, this is just my opinion, but I though it will help you to get the idea of the problem.

Sorry,
—SA
P.S.: I can imagine outrage caused by this post, as well as down-votes. You're welcome!
However, I would eagerly want to see anything that could seed a doubt in my opinion. Right now I think that I can spot a forgery on every single image created via automated image processing. I will be highly excited if anyone can proof otherwise. Any suggestions?


Deepak,



让我们从你的声明开始,你可以将像素分类为背景(在你的背景中)例如白色的,你画的是红色的)或不是背景。



边缘的效果确实很糟糕,因为背景很明显/不是背景。为了获得更好的结果,你必须使用模糊逻辑并允许纯背景和纯非背景之间的一些中间度,让我们说前景。换句话说,为每个像素分配一个alpha不透明度,从0到255(而不是0/1)。



现在你如何分配alpha值?所有背景像素(接近白色)将获得不透明度0.距离任何背景像素至少两个像素的像素将被任意视为前景并获得不透明度255.在图像处理术语中,您将侵蚀非背景区域。我们任意假设边缘是两个像素宽。



对于剩余的未分类像素,您将考虑最近的背景像素和最近的前景像素(在几何意义上最接近)并指定一个透明度计算为 255 * D(像素,背景像素)/ D(前景像素,背景像素),其中 D 是色彩空间的距离。



这个主题可以有不同的变化。主要的挑战是确定当地的真实背景和前瞻性颜色,并找出它们混合的比例。



还要注意一些中间像素(如果是薄的特征) )将没有前景邻居,他们的alpha值是任意的。



我不是说这会给你完美的消光,因为它是一种相当粗糙的方法,但是它应该会减少楼梯效应。
Deepak,

let us start with your statement that you can classify the pixels as being background (in your example the white ones, that you painted red) or not background.

The effect along edges is indeed awful because of the sharp decision background/not background. To achieve better results, you must use fuzzy logics and allow some intermediate degree between pure background and pure non-background, let us say foreground. In other words, assign every pixel an alpha opacity, from 0 to 255 (instead of just 0/1).

Now how do you assign the alpha values ? All your background pixels (close to white color) will get opacity 0. The pixels at least two pixels away from any background pixels will be arbitrarily considered foreground and get opacity 255. In image processing terminology, you will erode the non-background areas. We arbitrarily assume that edges are two pixels wide.

For the remaining unclassified pixels, you will consider the nearest background pixel and nearest foreground pixel (nearest in the geometric sense) and assign a transparency computed as 255 * D(pixel, background pixel) / D(foreground pixel, background pixel), where D are distances in color space.

There can be different variations on this theme. The main challenge is to determine the true background and foregound colors locally and find in what proportion they were mixed.

Also note that some intermediate pixels (in case of thin features) will have no foreground neighbor and their alpha value is arbitrary.

I don't mean that this will give you perfect matting as it is a rather crude method, but it should diminish the staircase effect.


这篇关于从照片中减去图像背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆