“imfilter”和“imfilter”之间的差异和“conv2” [MATLAB]

发布于 2024-12-12 06:03:40 字数 293 浏览 6 评论 0原文

我使用这两个函数来查找刻度上的边缘。您有一个输入图像,您可以将蒙版(例如 prewitt)应用于输入图像,并获得结果图片。

mypic = imread('examplepic.jpg')
hy = fspecial('prewitt')
yimfilter = imfilter(mypic,hy) % Using imfilter
yconv2 = conv2(mypic,hy) % Using conv2

这两者在理论上有什么区别?我知道我得到了不同的输出,但有什么区别呢?

谢谢

I use this both function to find edges on a scale. You have a input image, you apply a mask (for ex. prewitt) to the input image, and get the resultant pic.

mypic = imread('examplepic.jpg')
hy = fspecial('prewitt')
yimfilter = imfilter(mypic,hy) % Using imfilter
yconv2 = conv2(mypic,hy) % Using conv2

Which is the theorical difference between these two? I know I got different outputs, but which is the difference?

Thanks

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

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

发布评论

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

评论(2

迟月 2024-12-19 06:03:40

conv2 输出整个 2-D 卷积,这意味着 yconv2 将比 mypic 大。另一方面,imfilter 默认情况下会修剪卷积的边缘,以便 yimfilter 的大小应与 mypic 相同。您可以让 imfilter 像 conv2 一样离开整个卷积,但这不是它的默认行为。

还有其他差异:imfilter 的“复制”选项,imfilter 可以在任意数量的维度(不仅仅是 2)上进行卷积,等等,但我认为您没有问这个。

conv2 outputs the entire 2-D convolution, which means that yconv2 will be bigger than mypic. imfilter, on the other hand, by default trims the edges of the convolution so that yimfilter should be the same size as mypic. You can make imfilter leave the entire convolution like conv2 does, but that is not its default behavior.

There are other differences: imfilter's "replicate" option, imfilter can do convolution on arbitrary numbers of dimensions (not just 2), and so on, but I don't think you were asking about that.

半﹌身腐败 2024-12-19 06:03:40

嗯,imfilter 默认情况下使用相关性,而不是卷积。如果您调用

yimfilter = imfilter(mypic,hy,'conv')

,则 yconv2yimfilter 将是相同的。至于相关和卷积之间的区别,如果您使用一维卷积/相关掩模,您可以很容易地看到它。输出将是相同的,只是移动了行/列(取决于掩码的方向)。

顺便说一句,如果你调用

yimfilter = imfilter(mypic,hy)
yfilter2 = filter2(hy,mypic)

你会发现 yimfilteryfilter2 是相同的,因为 filter2 也使用了相关性。

Well, imfilter by default uses correlation, not convolution. If you call

yimfilter = imfilter(mypic,hy,'conv')

then yconv2 and yimfilter will be the same. As for the difference between correlation and convolution, well you can see it quite easily if you use a 1D convolution/correlation mask. The output will be the same, just shifted of a row/column (depending on the direction of the mask).

By the way, if you call

yimfilter = imfilter(mypic,hy)
yfilter2 = filter2(hy,mypic)

you'll find that yimfilter and yfilter2 are the same, because filter2 also uses correlation.

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