what is the difference between conv2, filter2 and imfilter..?
Mostra commenti meno recenti
I am confused with the way these three algorithms works. which function should i use for gaussian, prewitt etc. filters??
Risposta accettata
Più risposte (2)
Alex Taylor
il 7 Ott 2011
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 Commento
Chris Turnes
il 11 Ago 2017
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
il 5 Ott 2011
0 voti
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.
Categorie
Scopri di più su Get Started with MATLAB in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!