Main Content

colfilt

Column-wise neighborhood operations

Description

example

B= colfilt(A,[m n],block_type,fun)processes the imageAby rearranging eachm-by-nblock ofAinto a column of a temporary matrix, and then applying the functionfunto this matrix.colfiltzero-padsA, if necessary.

B= colfilt(A,[m n],[mblock nblock],block_type,fun)subdividesAinto regions of sizemblock-by-nblockblocks to save memory. Note that the result of the operation does not change when using the[mblock nblock]argument.

For example, if[mblock nblock]is[3 4]and the size of each block is 16-by-16 pixels, thencolfiltsubdivides the image into regions of size 48-by-64 pixels and processes each region separately.

B= colfilt(A,'indexed',___)processesAas an indexed image, padding with0s if the class ofAisuint8,uint16, orlogical, and padding with1s otherwise.

Examples

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 column-wise neighborhood processing.

Read a grayscale image into the workspace.

I = imread('tire.tif');

Perform column-wise filtering. The functionmeanis called on each 5-by-5 pixel neighborhood.

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

Display the original image and the filtered image.

imshow(I) title('Original Image')

Figure contains an axes object. The axes object with title Original Image contains an object of type image.

图imshow (I2)标题('Filtered Image')

Figure contains an axes object. The axes object with title Filtered Image contains an object of type image.

Input Arguments

collapse all

Image, specified as an array of any class supported byfun.

集团k size, specified as a 2-element vector of positive integers.mis the number of rows andnis the number of columns in each block.

集团k group size, specified as a 2-element vector of positive integers.mblockis the number of blocks in the group in the vertical direction, andnblockis the number of blocks in the group in the horizontal direction.

集团k type, specified as'sliding'for sliding neighborhoods or'distinct'for distinct blocks.

Data Types:char|string

Function handle, specified as a handle. The input and output arguments to this function depend on the value ofblock_type. For more information, seeAlgorithms.

For more information about function handles, seeCreate Function Handle.

Output Arguments

collapse all

Filtered image, returned as a numeric matrix.

Algorithms

The algorithm thatcolfiltuses to process images depends on the value ofblock_type.

Value

Description

'distinct'

  • First,colfiltrearranges eachm-by-nblock ofAinto a column in a temporary matrix by using theim2colfunction.

  • Next,colfiltapplies the functionfunto this temporary matrix.funmust return a matrix the same size as the temporary matrix.

  • Finally,colfiltrearranges the columns of the matrix returned byfunintom-by-ndistinct blocks, by using thecol2imfunction.

'sliding'

  • First,colfiltrearranges eachm-by-nneighborhood ofAinto a column in a temporary matrix by using theim2colfunction.

  • Next,colfiltapplies the functionfunto this temporary matrix.fun必须返回一个行向量,其中包含一个值for each column in the temporary matrix. (Column compression functions such assumreturn the appropriate type of output.)

  • Finally,colfiltreshapes the vector returned byfuninto a matrix the same size asA, by using thereshapefunction.

To save memory, thecolfiltfunction might divideAinto subimages and process one subimage at a time. This implies thatfunmay be called multiple times, and that the first argument tofunmay have a different number of columns each time.

Introduced before R2006a