Image Processing Toolbox    
colfilt

Perform neighborhood operations using column-wise functions

Syntax

Description

colfilt processes distinct or sliding blocks as columns. colfilt can perform similar operations to blkproc and nlfilter, but often executes much faster.

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 can be a function_handle, created using @, or an inline object. 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 a string with one of these values:

B = colfilt(A,[m n],'distinct',fun) 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 of the same size as the temporary matrix. colfilt then rearranges the columns of the matrix returned by fun into m-by-n distinct blocks.

B = colfilt(A,[m n],'sliding',fun) 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 of the same size as A.

B = colfilt(A,[m n],block_type,fun,P1,P2,...) passes the additional parameters P1,P2,..., to fun. The colfilt function calls fun using,

where x is the temporary matrix before processing, and y is the temporary matrix after processing.

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 zeros if the class of A is uint8 or uint16, or ones if the class of A is double.

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.

Example

This example sets each output pixel to the mean value of the input pixel's 5-by-5 neighborhood.

See Also

blkproc, col2im, im2col, nlfilter


  col2im colorbar