“imfilter”和“imfilter”之间的差异和“conv2” [MATLAB]
我使用这两个函数来查找刻度上的边缘。您有一个输入图像,您可以将蒙版(例如 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
嗯,
imfilter
默认情况下使用相关性,而不是卷积。如果您调用,则
yconv2
和yimfilter
将是相同的。至于相关和卷积之间的区别,如果您使用一维卷积/相关掩模,您可以很容易地看到它。输出将是相同的,只是移动了行/列(取决于掩码的方向)。顺便说一句,如果你调用
你会发现
yimfilter
和yfilter2
是相同的,因为filter2
也使用了相关性。Well,
imfilter
by default uses correlation, not convolution. If you callthen
yconv2
andyimfilter
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
you'll find that
yimfilter
andyfilter2
are the same, becausefilter2
also uses correlation.