What is the difference between conv2 and imfilter?

Illustration
Holden - 2020-10-16T10:18:43+00:00
Question: What is the difference between conv2 and imfilter?

i am trying to convolute an image (512x512) with a filter (3x3) .For this process i am using both covv2() and imfilter() . These functions are supposed to do the same but after the convolution in the first case(conv2) i am getting a new image 516x516 and in the second case (imfilter) i am getting a new image 514x514 .Why is this happening?

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

The two main reasons. One is that imfilter has options to not flip the filter window like convolution does (the correlation option), or to flip it like convolution does. If your fliter is radially symmetric or uniform, there is no difference.
The second reason is how they handle edge effects. imfilter() has a lot more options for what to do when the filter window gets near ("falls off") the edge of the image. But imfilter() returns an image of the same size and class as the input whereas conv2() returns a floating point image, but has options to give the "full" size convolution, which gives values even when the center of the filter is off the image but some parts of the filter still overlap the image.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!