Herror ::rank_image (
    Hobject Image,
    Hobject Mask,
    Hobject *ImageRank,
    const HTuple &Rank,
    const HTuple &Margin
)
HImage HImage::RankImage (
    const HRegion &Mask,
    const HTuple &Rank,
    const HTuple &Margin
) const
HImageArray HImageArray::RankImage (
    const HRegion &Mask,
    const HTuple &Rank,
    const HTuple &Margin
) const

Smooth an image with an arbitrary rank mask.

The operator ::rank_image carries out a non-linear smoothing of the gray values of all input images (Image). The filter mask (Mask) is transmitted as a region. In contrast to many other filters you can choose an arbitrary shape, e.g., by using operators like ::gen_circle or ::draw_region. The position of the mask region has no influence on the result; the center of gravity of the region is used as the reference point of the filter mask.

The specified mask is moved over the image to be filtered in such a way that the reference point of the mask touches all pixels once. At each position a histogram is calculated from the gray values of all pixels covered by the mask. By specifying Rank = 1 the lowest (= darkest) gray value appearing in the histogram is selected and entered as resulting gray value in the output image ImageRank; if Rank corresponds to the number of pixels of the filter mask, i.e., its area, the brightest gray value is selected. This behavior is idential to the erosion/dilation operators in gray morphology (::gray_erosion, ::gray_dilation). If you use a rank that is equal to half of the pixels of the filter mask you get the same behavior as for the the median filter (::median_image).

You can use ::rank_image to eliminate noise, to eliminate structures with a given orientation (use ::gen_rectangle2 to create the mask region), or as an advanced gray morphologic operator that is more robust against noise. In this case you will not use 1 or the mask area as rank values, but a slightly higher or lower value, respectively.

Several margin controls can be chosen for filtering (Margin):

    0...255   Pixels outside of the image edges
              are assumed to be constant (with the indicated
              gray value).
    -1        Continuation of edge pixels.
    -2        Cyclic continuation of image edges.
    -3        Reflection of pixels at the image edges.


Parameters

Image (input_object)
multichannel-image(-array) -> Hobject: HImage(Array) ( byte )
Image to be filtered.

Mask (input_object)
region -> Hobject: HRegion ( byte )
Region serving as filter mask.

ImageRank (output_object)
multichannel-image(-array) -> Hobject * : HImage(Array)
Filtered image.

Rank (input_control)
integer -> HTuple.long
Rank of the output gray value in the sorted sequence of input gray values inside the filter mask. Typical value (median): area(mask) / 2.
Default value: 5
Suggested values: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31
Typical range of values: 1 <= Rank <= 512
Minimum increment: 1
Recommended increment: 2

Margin (input_control)
integer -> HTuple.long
Margin control: 0...255 (constant), -1 (edge pixels continued), -2 (cyclic continuation), -3 (reflection).
Default value: -3
Typical range of values: -3 <= Margin <= 255


Example
read_image(&Image,"fabrik");
draw_region(&Region,WindowHandle);
rank_image(Image,Region,&ImageRank,5,-3,);
disp_image(ImageRank,WindowHandle);

Complexity

For each pixel: O(sqrt(F) * 5) with F = area of Mask.


Result

If the parameter values are correct the operator ::rank_image returns the value H_MSG_TRUE. The behavior in case of empty input (no input images available) is set via the operator ::set_system('no_object_result',<Result>). If necessary an exception handling is raised.


Possible Predecessors

::read_image, ::draw_region, ::gen_circle, ::gen_rectangle1


Possible Successors

::threshold, ::dyn_threshold, ::regiongrowing


Alternatives

::sigma_image


See also

::gen_circle, ::gen_rectangle1, ::gray_erosion_rect, ::gray_dilation_rect


References

R. Haralick, L. Shapiro; ``Computer and Robot Vision''; Addison-Wesley, 1992, Seite 318-320


Module

Image filters



Copyright © 1996-2002 MVTec Software GmbH