MATLAB 中的背景减法

发布于 2024-09-05 08:22:39 字数 364 浏览 7 评论 0原文

我正在寻找对图像进行背景减去。我是 MATLAB 新手,也是图像处理/分析新手,如果这听起来很愚蠢,我很抱歉。 1)除了 imsubtract() 之外,还有其他方法可以进行背景减去(除了将一张图像与另一张图像进行比较之外)吗? 2) 在 Math Works imsubtract 的说明( )为什么他们将其结构元素做成磁盘?到目前为止,这似乎相当困难,因为每次我尝试一些东西时,我最终不仅会减去嘈杂的背景,而且还会丢失我想要查看的图像部分!

I'm looking to do background subtracting on an image. I'm new to MATLAB and new to image processing/analysis, so sorry if any of this sounds stupid. 1) Other than imsubtract() are there other ways to do background subtracting (besides comparing one image to another)? 2) In the Math Works explanation for imsubtract() why do they make their structuring element a disk? This seems rather difficult so far because every time I try something, I end up not only subtracting the noisy background but also losing the parts of the image I want to look at!

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

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

发布评论

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

评论(3

悲欢浪云 2024-09-12 08:22:39

您使用什么样的图像?

背景扣除很容易。如果您想减去一个常数值或与图像大小相同的背景,您只需编写 img = img - background 即可。 imsubtract 只是确保当背景大于图像时输出为零。

背景估计很困难。在那里你需要知道你正在看什么类型的图像,否则背景估计将会失败。

例如,如果您的点或线特征要么在明亮的背景上全黑,要么在黑暗的背景上明亮,则可以使用局部最大过滤器 (imdilate) 或局部最小过滤器 (< code>imerode) 分别大于您的特征,因此无论您在何处放置滤镜蒙版,都会有一些像素覆盖背景。另外,您希望过滤器的形状与特征有些相似。就您而言,如果丢失了部分图像,您可能需要尝试使过滤器变大(但不要太大)。

不用减去最大值或最小值,减去中值也可以很好地工作,尽管您必须选择过滤器大小,以便过滤器蒙版内通常有大部分背景像素。不幸的是,中值滤波相当慢。

What kind of image do you work with?

Background subtraction is easy. If you want to subtract a constant value, or a background with the same size as your image, you simply write img = img - background. imsubtract simply makes sure that the output is zero wherever the background is larger than the image.

Background estimation is hard. There you need to know what kind of image you're looking at, otherwise, the background estimation will fail.

If you have, for example, spot or line features that are either all dark on bright or bright on dark background, you can pass through with a local maximum filter (imdilate) or a local minimum filter (imerode), respectively, that is larger than your features, so that wherever you place the filter mask, there are some pixels that cover background. Also, you want the filter to have somewhat similar shape as the features. In your case, if you lose part of your image, you may want to try and make the filter larger (but not too large).

Instead of subtracting maximum or minimum, subtracting the median can work well, though you have to choose the filter size such that there's usually a majority of background pixels inside the filter mask. Unfortunately, median filtering is rather slow.

£烟消云散 2024-09-12 08:22:39

要减去背景图像,您需要背景模型。最简单的模型是作为背景捕获的图像以及一些允许的偏差(+/- 0-255)。然后,MATLAB 中的背景减法非常简单:

image( find(abs(image-background) <= Threshold) ) = 0;

当您使用统计模型时,这会变得更加困难,但本质上减去背景非常容易。 imsubtract 不是背景扣除;它是一个减法滤镜,就像您在 Photoshop 中看到的那样。它不关心背景与前景,这就失去了重点。

由于背景扣除本身非常简单,因此问题更多地与背景估计有关。这有点复杂,通常需要更多的帧和训练来构建背景的统计模型(例如,将像素视为高斯分布或高斯混合,或者查看光流以确定不移动的部分)。

如果您可以(通过工作或学校)访问技术文章,Wren 和其他人撰写的“Pfinder:实时跟踪人体”提供了一种非常简单的方法。或者你可以在谷歌上搜索单高斯背景减法。这里有很多用OpenCV实现的方法 --> http://dparks.wikidot.com/source-code <-- 您可能会发现有用。

To subtract the background image, you need a model of the background. The simplest model is an image captured as the background along with some allowable deviation (+/- 0-255). Then, background subtraction in MATLAB is pretty simple:

image( find(abs(image-background) <= threshold) ) = 0;

It becomes more difficult when you use a statistical model, but essentially subtracting the background is pretty easy. imsubtract is NOT background subtraction; it is a subtraction filter like you would find in photoshop. It does not care about background versus foreground, which then defeats the point.

Since background subtraction itself is pretty easy, the question becomes more about background estimation. This is a bit more complicated, and generally requires more frames and training to build statistical models of the background (for example, looking at pixels as Gaussian distributions or mixtures of Gaussians, or looking instead at optical flow to determine what's not moving).

If you have access to technical articles (via work or school), "Pfinder: Real-Time Tracking of the Human Body" by Wren and others gives a pretty simple approach. Or you can just search google for single Gaussian background subtraction. There are a number of methods implemented with OpenCV here --> http://dparks.wikidot.com/source-code <-- that you might find useful.

毁梦 2024-09-12 08:22:39

计算机视觉系统工具箱具有计算机视觉系统工具箱。 mathworks.com/help/vision/ref/vision.foregroundDetectorclass.html" rel="nofollow">vision.ForegroundDetector 对象,它实现了 Stauffer 和 Grimson 的 GMM 背景减除的变体。利用多个核心,实施速度非常快。查看这个示例,了解如何使用背景减法作为跟踪多个对象的系统的构建块。

The Computer Vision System Toolbox has the vision.ForegroundDetector object, which implements a variant of Stauffer and Grimson's GMM background subtraction. The implementation is very fast, leveraging multiple cores. Check out this example of how to use background subtraction as a building block of a system for tracking multiple objects.

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