Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between 'imfilter' and 'conv2' [MATLAB]

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

like image 649
user981227 Avatar asked Jan 18 '23 10:01

user981227


1 Answers

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.

like image 50
Jim Clay Avatar answered Feb 01 '23 18:02

Jim Clay