This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Columnwise neighborhood operations


B = colfilt(A,[m n],block_type,fun)
B = colfilt(A,[m n],[mblock nblock],block_type,fun)
B = colfilt(A,'indexed',...)


B = colfilt(A,[m n],block_type,fun) processes the image A by rearranging each m-by-n block of A into a column of a temporary matrix, and then applying the function fun to this matrix. fun must be a function handle. The function colfilt zero-pads A, if necessary.

Before calling fun, colfilt calls im2col to create the temporary matrix. After calling fun, colfilt rearranges the columns of the matrix back into m-by-n blocks using col2im.

block_type is one of the values listed in this table.


colfilt can perform operations similar to blockproc and nlfilter, but often executes much faster.




Rearranges each m-by-n distinct block of A into a column in a temporary matrix, and then applies the function fun to this matrix. fun must return a matrix the same size as the temporary matrix. colfilt then rearranges the columns of the matrix returned by fun into m-by-n distinct blocks.


Rearranges each m-by-n sliding neighborhood of A into a column in a temporary matrix, and then applies the function fun to this matrix. fun must return a row vector containing a single value for each column in the temporary matrix. (Column compression functions such as sum return the appropriate type of output.) colfilt then rearranges the vector returned by fun into a matrix the same size as A.

B = colfilt(A,[m n],[mblock nblock],block_type,fun) processes the matrix A as above, but in blocks of size mblock-by-nblock to save memory. Note that using the [mblock nblock] argument does not change the result of the operation.

B = colfilt(A,'indexed',...) processes A as an indexed image, padding with 0's if the class of A is uint8 or uint16, or 1's if the class of A is double or single.


To save memory, the colfilt function might divide A into subimages and process one subimage at a time. This implies that fun may be called multiple times, and that the first argument to fun may have a different number of columns each time.

Class Support

The input image A can be of any class supported by fun. The class of B depends on the class of the output from fun.


collapse all

This example shows how to set each output pixel to the mean value of the input pixel's 5-by-5 neighborhood using columnwise neighborhood processing.

Read a grayscale image into the workspace.

I = imread('tire.tif');

Perform columnwise filtering. The function mean is called on each 5-by-5 pixel neighborhood.

I2 = uint8(colfilt(I,[5 5],'sliding',@mean));

Display the original image and the filtered image.

title('Original Image')

title('Filtered Image')

Introduced before R2006a

Was this topic helpful?