what is the difference between conv2, filter2 and imfilter..?
古いコメントを表示
I am confused with the way these three algorithms works. which function should i use for gaussian, prewitt etc. filters??
採用された回答
その他の回答 (2 件)
Alex Taylor
2011 年 10 月 7 日
Hi Jigar,
Good question, and everyone else has provided a lot of great information. I'd like to add a bit, hopefully it'll be useful.
1) imfilter performs correlation by default. However, it will also return the convolution result if you supply 'conv' as an optional argument:
out = imfilter(a,h,'conv');
2) By default, conv2 gives the full filtered result. This is different than the default behavior of imfilter, which yields the output as the same size as the input. Both conv2 and imfilter provide optional arguments which can be used to get either result, which is to say:
imfilter(a,h,'conv')
is the same as
conv2(a,h,'same')
within double precision floating point error.
3) I'll give a few rules of thumb about performance based on the current state of the code. Both imfilter and conv2 are hardware optimized and multi-threaded. For floating point inputs, the performance of both will be roughly equivalent. For integer input images, imfilter will be faster because it has integer optimized code paths. For linearly separable filter kernels, imfilter does separation of the kernel into row and column vectors, as other people have pointed out. I'm not sure whether conv2 performs this optimization.
Hope this helps,
Alex.
1 件のコメント
Chris Turnes
2017 年 8 月 11 日
To add one bit of further clarity, conv2 will not analyze an input to determine if a kernel is separable and then decompose it into the separable parts. However, if you know in advance that the kernel is separable, you can use the three-input syntax conv2(u,v,A), which indeed performs a separable convolution.
Sean de Wolski
2011 年 10 月 5 日
0 投票
TMW recommends imfilter if you have the IPT and are working with images. Personally, I only use conv2 since I hate the conversion to uint8 and often want (at least temporary) values above 255.
カテゴリ
ヘルプ センター および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!