图像处理中的平均掩模和拉普拉斯掩模

发布于 2024-11-15 08:55:41 字数 87 浏览 3 评论 0原文

在给定的应用程序中,我对输入图像应用平均掩模以减少噪声,然后应用拉普拉斯掩模来增强小细节。有人知道如果我在Matlab中颠倒这些操作的顺序是否会得到相同的结果?

in a given application I apply an averaging mask to input images to reduce noise, and then a Laplacian mask to enhance small details. Anyone knows if I Would get the same results if I reverse the order of these operations in Matlab?

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

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

发布评论

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

评论(3

把梦留给海 2024-11-22 08:55:41

与拉普拉斯核进行卷积类似于使用有关强度变化的二阶导数信息。由于该导数对噪声敏感,因此我们通常在应用拉普拉斯滤波器之前使用高斯平滑图像。


这是一个 MATLAB 示例,类似于 @belisarius 发布:

f='http://upload.wikimedia.org/wikipedia/commons/f/f4/Noise_salt_and_pepper.png';
I = imread(f);

kAvg = fspecial('average',[5 5]);
kLap = fspecial('laplacian',0.2);

lapMask = @(I) imsubtract(I,imfilter(I,kLap));

subplot(131), imshow(I)
subplot(132), imshow( imfilter(lapMask(I),kAvg) )
subplot(133), imshow( lapMask(imfilter(I,kAvg)) )

在此处输入图像描述

Convolving with a Laplacian kernel is similar to using second derivative information about the intensity changes. Since this derivative is sensitive to noise, we often smooth the image with a Gaussian before applying the Laplacian filter.


Here's a MATLAB example similar to what @belisarius posted:

f='http://upload.wikimedia.org/wikipedia/commons/f/f4/Noise_salt_and_pepper.png';
I = imread(f);

kAvg = fspecial('average',[5 5]);
kLap = fspecial('laplacian',0.2);

lapMask = @(I) imsubtract(I,imfilter(I,kLap));

subplot(131), imshow(I)
subplot(132), imshow( imfilter(lapMask(I),kAvg) )
subplot(133), imshow( lapMask(imfilter(I,kAvg)) )

enter image description here

毅然前行 2024-11-22 08:55:41

假设您有两个滤镜 F1F2,以及一个图像 I。如果您将图像通过两个过滤器,您将得到一个定义为“

X = ((I * F1) * F2)

此处我使用 * 来表示 卷积

根据卷积的关联规则,这是相同的。

X = (I * (F1 * F2))

使用交换性,我们可以说,

X = (I * (F2 * F1)) = ((I * F2) * F1)

当然,这是在数学的连续域中,在机器上执行这些操作意味着会出现舍入错误,并且可能会丢失一些数据。您还应该考虑您的过滤器是否是 FIR,否则考虑数字过滤的整个概念当卷积开始崩溃时,你的过滤器不能真正按照你想要的方式运行。


编辑

离散卷积定义为

因此在数据边缘添加零不会改变数学意义上的任何内容。

正如一些人指出的那样,您会在数字上得到不同的答案,但每当我们处理计算实际数据时,这是预期的。这些变化应该很小,并且仅限于卷积输出的低能量分量(即:边缘)。

考虑卷积运算的工作原理也很重要。对长度为 X 和长度 Y 的两组数据进行卷积将得到长度为 X+Y-1 的答案。 MATLAB 和 Mathematica 等程序在幕后发生了一些神奇的事情,可以为您提供长度为 XY 的答案。

因此,对于@belisarius 的帖子,我们似乎确实在说同样的事情。

Lets say you have two filters F1 and F2, and an image I. If you pass your image through the two filters, you would get a response that was defined as

X = ((I * F1) * F2)

Where here I am using * to represent convolution.

By the associative rule of convolution, this is the same as.

X = (I * (F1 * F2))

using commutativity, we can say that

X = (I * (F2 * F1)) = ((I * F2) * F1)

Of course, this is in the nice continuous domain of math, doing these things on a machine means there will be rounding errors and some data may be lost. You also should think about if your filters are FIR, otherwise the whole concept of thinking about digital filtering as convolution sorta starts to break down as your filter can't really behave the way you wanted it to.


EDIT

The discrete convolution is defined as

conv2 uses a straightforward formal implementation of the two-dimensional convolution equation in spatial form

so adding zeros at the edges of you data doesn't change anything in a mathematical sense.

As some people have pointed out, you will get different answers numerically, but this is expected whenever we deal with computing actual data. These variations should be small and limited to the low energy components of the output of the convolution (i.e: the edges).

It is also important to consider how the convolution operation is working. Convolving two sets of data of length X and length Y will result in an answer that is X+Y-1 in length. There is some behind the scenes magic going on for programs like MATLAB and Mathematica to give you an answer that is of length X or Y.

So in regards to @belisarius' post, it would seem we are really saying the same thing.

强者自强 2024-11-22 08:55:41

从数字上看,结果并不相同,但图像看起来非常相似。

Mathematica 中的示例:

在此处输入图像描述

编辑

作为对 @thron 在其关于线性滤波器和填充的换向的回答中评论的回答,只需考虑以下操作。

虽然没有填充的高斯和拉普拉斯滤波器的换向是正确的:

list = {1, 3, 5, 7, 5, 3, 1};
gauss[x_] := GaussianFilter[ x, 1]
lapl[x_] := LaplacianFilter[x, 1]
Print[gauss[lapl[list]], lapl[gauss[list]]]
(*
->{5.15139,0.568439,-1.13688,-9.16589,-1.13688,0.568439,5.15139}    
  {5.15139,0.568439,-1.13688,-9.16589,-1.13688,0.568439,5.15139}
*)

使用填充做同样的事情,会导致边缘处的差异:

gauss[x_] := GaussianFilter[ x, 1, Padding -> 1]
lapl[x_] := LaplacianFilter[x, 1, Padding -> 1]
Print[gauss[lapl[list]], lapl[gauss[list]]]

(*
->{4.68233,0.568439,-1.13688,-9.16589,-1.13688,0.568439,4.68233}
  {4.58295,0.568439,-1.13688,-9.16589,-1.13688,0.568439,4.58295}
*)

Numerically the results are not the same, but the images look pretty similar.

Example in Mathematica:

enter image description here

Edit

As an answer to @thron comment in his answer about commutation of linear filters and padding, just consider the following operations.

While commutation of a Gaussian and Laplacian filter without padding is true:

list = {1, 3, 5, 7, 5, 3, 1};
gauss[x_] := GaussianFilter[ x, 1]
lapl[x_] := LaplacianFilter[x, 1]
Print[gauss[lapl[list]], lapl[gauss[list]]]
(*
->{5.15139,0.568439,-1.13688,-9.16589,-1.13688,0.568439,5.15139}    
  {5.15139,0.568439,-1.13688,-9.16589,-1.13688,0.568439,5.15139}
*)

Doing the same with padding, result in a difference at the edges:

gauss[x_] := GaussianFilter[ x, 1, Padding -> 1]
lapl[x_] := LaplacianFilter[x, 1, Padding -> 1]
Print[gauss[lapl[list]], lapl[gauss[list]]]

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