如何在C#中删除图像的背景 [英] How to remove background of an image in c#

查看:114
本文介绍了如何在C#中删除图像的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除图像的背景?

推荐答案

pl检查以下帖子:

http://stackoverflow.com/questions/4905346/removing-image-background-scene [ ^ ]
pl check the the following post:

http://stackoverflow.com/questions/4905346/removing-image-background-scene[^]


亲爱的朋友,

这是给您的链接:-

http://www.oliveragustin.com/background-subtraction-in-c/ [ ^ ]

但这仅适用于背景中的一幅图像.

谢谢
Dear Friend,

This is the link for you:-

http://www.oliveragustin.com/background-subtraction-in-c/[^]

But this will work for only one image in background.

Thanks


以任何有意义的方式回答您的问题:我们需要确切地知道您所说的背景".

例如:考虑四种不同的情况:

0.您既有只带有背景的图像,又有想要在精确相同背景上提取内容的图像.这导致了另一种类型的解决方案,在更简单的代码中可能更容易实现.

但是,如果第二张图像(具有您要提取的内容)已将该内容反混叠到背景中:您处于深水区(请参阅下面的#3).

1.一幅将背景定义为一种独特颜色的图像:该颜色的每个像素都将被消除.最简单的情况.很容易做到.

稍微复杂一点的变化可能是一个源图像,对于它来说,您可以说在RBG颜色空间中具有红色值的每个像素都是要删除的背景.

而且,对于HSL,CMYK或LAB颜色空间中的图像:上述内容可能会有变化,可能有用或可能没有用,这在很大程度上取决于特定的源图像.

2.一幅具有清晰定义的边框颜色的图像,仅边界是唯一的,它定义了封闭的形状:您的目标是删除清晰定义的颜色边框之外的所有内容.更复杂:您必须针对每个像素区分边界颜色之外的颜色.

现在想象一下,通过有一个包含多个闭合形状的图像来进一步升级此方案:您将所有形状之外的所有内容都删除了.更复杂.

现在,想象一下这种变化:您的目标是删除具有特定边框颜色的图像中封闭形状内部的内容,该颜色对于边框而言是唯一的.

3.一个人头的图像,该图像位于多色背景上,并且经过了抗锯齿处理,以使观看者看得更清楚,没有锯齿".更复杂;其实很复杂.

除了这些案例,您还将进入非常复杂的形状识别和图像提取的计算机科学领域,在这里,您甚至可以进入博士学位.级别.

在此期间,除非您尝试执行这些任务中最简单的操作...#0在第二张图像中没有抗锯齿,或者#1 ...我建议您使用GIMP或PhotoShop,并学习如何使用他们用于此类任务的出色工具.
To answer your question in any meaningful way: we need to know exactly what you mean by "background."

For example: consider four different scenarios:

0. you have both an image with the background only, and an image with the content you wish to extract on that exact same background. That leads to another type of solution, which is probably much more achievable in simpler code.

However, if the second image, with the content you wish to extract, has had that content anti-aliased into the background: you are in some deep waters (see #3 below).

1. one image in which background is defined as one unique color: every pixel of that color is to be eliminated. simplest case. pretty easy to do.

A slightly more complex variation of this might be one source image for which you can say that every pixel that has any red color value in RBG color space is background to be removed.

And, with images in HSL, CMYK, or LAB color spaces: there could be variations on the above which may or may not be useful, depending very much on the specific source image.

2. one image with a sharply defined border color, unique to the border only, that defines a closed shape: your goal is to remove everything outside that sharply defined color border. more complex: you''ve got to discriminate, for every pixel, what is outside the border color.

Now imagine a further escalation of this scenario by having an image in which there are multiple closed shapes: and you remove everything outside the unique border color of all of them. even more complex.

And now, imagine another permutation of this: your goal is to remove the contents inside a closed shape in an image with some specific border color which is unique to the border.

3. one image, of, say, a human head, which is on a multi-color background, and which has been anti-aliased so that it appears to the viewer more clearly defined without "jaggies." much more complex; in fact, very complex.

Beyond these cases, you get into the very complex computer science area of shape recognition, and image extraction, where you can go very, very deep, yea even unto the Ph.D. level.

In the meantime, unless you are trying to do the simplest of these tasks ... #0 with no anti-aliasing in the second image, or, #1 ... I suggest you get GIMP or PhotoShop, and learn how to use their excellent tools for such tasks.


这篇关于如何在C#中删除图像的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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