Synopsis
Perform a rank filter on the pixels in an image.
Format
void MimRank(SrcImageBufId, DestImageBufId, StructElemBufId, Rank, ProcMode)
MIL_ID SrcImageBufId; | Source image buffer identifier |
MIL_ID DestImageBufId; | Destination image buffer identifier |
MIL_ID StructElemBufId; | Identifier of a structuring element buffer to be used as a mask |
long Rank; | Order of rank |
long ProcMode; | Processing mode |
Description
This function performs a rank filter operation on the specified source buffer. It replaces each pixel with that pixel in its neighborhood whose value is the specified rankth value in relation to others. It uses the specified structuring element as a mask. This mask determines the neighborhood size and which pixels in the neighborhood to ignore.
The SrcImageBufId parameter specifies the identifier of the data source of the operator. This parameter must be given an image buffer identifier.
The DestImageBufId parameter specifies the identifier of the destination of the results. This parameter must be given an image buffer identifier.
The StructElemBufId parameter specifies the identifier of the structuring element that will be used as a mask. The structuring element buffer dimensions are used as the neighborhood size. Values in the structuring element set to M_DONT_CARE represent neighborhood pixels not to be considered in the ranking operation. All other values in the structuring element must be set to 1, representing neighborhood pixels to be considered in the ranking operation. You can either define your own structuring element to be used as a mask or you can use a predefined mask buffer.
If you use a custom structuring element, you must have previously allocated it with MbufAlloc1d or MbufAlloc2d (specifying M_STRUCT_ELEMENT as the attribute) and loaded it with values, using MbufPut.
The following are predefined mask buffers:
M_3X3_RECT | Applies no mask and sets the neighborhood size to 3 x 3 pixels. |
M_3X3_CROSS | Applies a cross (+) mask and sets the neighborhood size to 3 x 3 pixels. The cross mask makes the function ignore the pixels located in the four corners of the neighborhood. |
The Rank parameter specifies which of the pixel values to select after valid neighborhood values are sorted in increasing order; valid neighborhood pixel values are those that are not masked-out. This parameter can be given a value in the range of 1 to the number of valid neighborhood pixels. If the number of valid pixels is less than the given rank, it is used as the rank.
If this parameter is set to M_MEDIAN, MimRank performs a median filter (that is, each pixel is replaced with the median neighborhood value).
The ProcMode parameter specifies the processing mode to use. This parameter can be set to the following:
M_BINARY | Non-zero pixels will be treated as ones (1) during processing and the resulting non-zero pixels will have the maximum value of the unsigned buffer (for example, 0xff for an 8-bit buffer). |
M_GRAYSCALE (default) |
The source image’s gray values are used for processing and the resulting buffer will also contain gray values. |
Note
This function is optimized for packed binary buffers.
Status
In-place processing is supported, but the source and destination image buffers cannot partially overlap (a situation that can only occur when using child buffers).