| Image Processing Toolbox |     ![]()  | 
Perform two-dimensional order-statistic filtering
Syntax
Description
B = ordfilt2(A,order,domain) replaces each element in A by the order-th element in the sorted set of neighbors specified by the nonzero elements in domain.
B = ordfilt2(A,order,domain,S), where S is the same size as domain, uses the values of S corresponding to the nonzero values of domain as additive offsets. 
B = ordfilt2(...,padopt) controls how the matrix boundaries are padded. Set padopt to 'zeros' (the default), or 'symmetric'. If padopt is 'zeros', A is padded with zeros at the boundaries. If padopt is 'symmetric', A is symmetrically extended at the boundaries.
Class Support
The class of A can be logical, uint8, uint16, or double. The class of B is the same as the class of A, unless the additive offset form of ordfilt2 is used, in which case the class of B is double. 
Remarks
domain is equivalent to the structuring element used for binary image operations. It is a matrix containing only 1's and 0's; the 1's define the neighborhood for the filtering operation.
For example, B = ordfilt2(A,5,ones(3,3)) implements a 3-by-3 median 
filter; B = ordfilt2(A,1,ones(3,3)) implements a 3-by-3 minimum filter; 
and B = ordfilt2(A,9,ones(3,3)) implements a 3-by-3 maximum filter. B = ordfilt2(A,1,[0 1 0; 1 0 1; 0 1 0]) replaces each element in A by the minimum of its north, east, south, and west neighbors. 
The syntax that includes S (the matrix of additive offsets) can be used to implement grayscale morphological operations, including grayscale dilation and erosion.
See Also
Reference
[1] Haralick, Robert M., and Linda G. Shapiro. Computer and Robot Vision, Volume I. Addison-Wesley, 1992.
   | ntsc2rgb | otf2psf | ![]()  |