Image Processing Toolbox    

The filter2 Function

In addition to the conv2 function, MATLAB also provides the filter2 function for two-dimensional linear filtering. filter2 can produce the same results as conv2, and differs primarily in that it takes a computational molecule as an input argument, rather than a convolution kernel. (filter2 operates by forming the convolution kernel from the computational molecule and then calling conv2.) The operation that filter2 performs is called correlation.

If k is a convolution kernel, h is the corresponding computational molecule, and A is an image matrix, the following calls produce identical results

and

The functions in the Image Processing Toolbox that produce filters (fspecial, fsample, etc.) all return computational molecules. You can use these filters directly with filter2, or you can rotate them 180 degrees and call conv2.


 Padding of Borders Separability