HALCON Reference Manual 10.0.2
Table of Contents / Filters / Smoothing ClassesClassesClasses | | | Operators

rank_imagerank_imagerank_imageRankImageRankImage (Operator)

Name

rank_imagerank_imagerank_imageRankImageRankImage — Compute a rank filter with arbitrary masks.

Signature

rank_image(Image, Mask : ImageRank : Rank, Margin : )

Herror rank_image(const Hobject Image, const Hobject Mask, Hobject* ImageRank, const Hlong Rank, const char* Margin)

Herror T_rank_image(const Hobject Image, const Hobject Mask, Hobject* ImageRank, const Htuple Rank, const Htuple Margin)

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

void HOperatorSetX.RankImage(
[in] IHUntypedObjectX* Image, [in] IHUntypedObjectX* Mask, [out] IHUntypedObjectX*ImageRank, [in] VARIANT Rank, [in] VARIANT Margin)

IHImageX* HImageX.RankImage(
[in] IHRegionX* Mask, [in] Hlong Rank, [in] VARIANT Margin)

static void HOperatorSet.RankImage(HObject image, HObject mask, out HObject imageRank, HTuple rank, HTuple margin)

HImage HImage.RankImage(HRegion mask, int rank, HTuple margin)

HImage HImage.RankImage(HRegion mask, int rank, string margin)

Description

rank_imagerank_imagerank_imageRankImageRankImage performs a rank filter on the input image ImageImageImageImageimage with a mask that is specified by the region MaskMaskMaskMaskmask and returns the filtered image in ImageRankImageRankImageRankImageRankimageRank. The shape of the mask can be chosen arbitrarily and can, for example, be created with operators like gen_circlegen_circlegen_circleGenCircleGenCircle or draw_regiondraw_regiondraw_regionDrawRegionDrawRegion. The position of the mask does not influence the result since the center of gravity of the mask region is used as the reference point of the mask.

Conceptually, the rank filter sorts all gray values within the mask in ascending order and then selects the gray value with rank RankRankRankRankrank. The rank 1 corresponds to the smallest gray value and the rank A corresponds to the largest gray value within the mask. Here, A denotes the area of MaskMaskMaskMaskmask (see area_centerarea_centerarea_centerAreaCenterAreaCenter). For RankRankRankRankrank = (A - 1) / 2 + 1, rank_imagerank_imagerank_imageRankImageRankImage returns the median gray value (see median_imagemedian_imagemedian_imageMedianImageMedianImage). For RankRankRankRankrank = 1, rank_imagerank_imagerank_imageRankImageRankImage performs a gray value erosion (see gray_erosion_rectgray_erosion_rectgray_erosion_rectGrayErosionRectGrayErosionRect, gray_erosion_shapegray_erosion_shapegray_erosion_shapeGrayErosionShapeGrayErosionShape, and gray_erosiongray_erosiongray_erosionGrayErosionGrayErosion), while for RankRankRankRankrank = A rank_imagerank_imagerank_imageRankImageRankImage performs a gray value dilation (see gray_dilation_rectgray_dilation_rectgray_dilation_rectGrayDilationRectGrayDilationRect, gray_dilation_shapegray_dilation_shapegray_dilation_shapeGrayDilationShapeGrayDilationShape, and gray_dilationgray_dilationgray_dilationGrayDilationGrayDilation).

rank_imagerank_imagerank_imageRankImageRankImage can be used, for example, to suppress noise or to suppress unwanted objects that are smaller than the mask. Furthermore, rank_imagerank_imagerank_imageRankImageRankImage is less sensitive to noise than the correponding gray value morphology operators. Therefore, to obtain a more robust version of the gray value morphology, instead of using 1 or A, slightly larger or smaller values should be selected for RankRankRankRankrank.

Several border treatments can be chosen for filtering via the parameter MarginMarginMarginMarginmargin:

    gray value   Pixels outside of the image borders are assumed to
                 be constant (with the specified gray value).
    'continued'  Continuation of border pixels.
    'cyclic'     Cyclic continuation of image borders.
    'mirrored'   Reflection of pixels at the image borders.

Attention

rank_imagerank_imagerank_imageRankImageRankImage uses an algorithm with a runtime per pixel that depends on the number of runs in the mask MaskMaskMaskMaskmask. Therefore, rank_imagerank_imagerank_imageRankImageRankImage is slower than rank_rectrank_rectrank_rectRankRectRankRect for rectangular masks with a large mask height. The precise mask height for which rank_rectrank_rectrank_rectRankRectRankRect will become faster than rank_imagerank_imagerank_imageRankImageRankImage depends on the computer architecture (processor type, availability of SIMD instructions like SSE2 or MMX, cache size and throughput, memory throughput). Typically, this is the case for mask heights > 15, but can also be the case only for larger mask sizes, e.g., if SIMD instructions are unavailable and memory throughput is low.

Furthermore, it should be noted that rank_rectrank_rectrank_rectRankRectRankRect uses a recursive implementation, which internally computes the filter response on the smallest enclosing rectangle of the domain of the input image. Therefore, if the domain of the input image only covers a small fraction of the smallest enclosing rectangle, it can happen that rank_imagerank_imagerank_imageRankImageRankImage is faster than rank_rectrank_rectrank_rectRankRectRankRect even for larger mask heights.

rank_imagerank_imagerank_imageRankImageRankImage should neither be used with RankRankRankRankrank = 1 to perform a gray value erosion nor with RankRankRankRankrank = A to perform a gray value dilation. In these cases, the operators gray_erosion_rectgray_erosion_rectgray_erosion_rectGrayErosionRectGrayErosionRect, gray_erosion_shapegray_erosion_shapegray_erosion_shapeGrayErosionShapeGrayErosionShape, or gray_erosiongray_erosiongray_erosionGrayErosionGrayErosion and gray_dilation_rectgray_dilation_rectgray_dilation_rectGrayDilationRectGrayDilationRect, gray_dilation_shapegray_dilation_shapegray_dilation_shapeGrayDilationShapeGrayDilationShape, or gray_dilationgray_dilationgray_dilationGrayDilationGrayDilation, respectively, are typically faster than rank_imagerank_imagerank_imageRankImageRankImage.

Parallelization

Parameters

ImageImageImageImageimage (input_object)  multichannel-image(-array) objectHImageHImageHImageXHobject (byte / int2 / uint2 / int4 / real)

Image to be filtered.

MaskMaskMaskMaskmask (input_object)  region objectHRegionHRegionHRegionXHobject

Filter mask.

ImageRankImageRankImageRankImageRankimageRank (output_object)  multichannel-image(-array) objectHImageHImageHImageXHobject * (byte / int2 / uint2 / int4 / real)

Filtered image.

RankRankRankRankrank (input_control)  integer HTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong)

Rank of the output gray value.

Default value: 5

Suggested values: 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 31, 49, 51, 61, 71, 81, 91, 101

Typical range of values: 1 ≤ Rank Rank Rank Rank rank ≤ 4095

Minimum increment: 1

Recommended increment: 2

MarginMarginMarginMarginmargin (input_control)  string HTupleHTupleVARIANTHtuple (string / integer / real) (string / int / long / double) (char* / Hlong / double) (BSTR / Hlong / double) (char* / Hlong / double)

Border treatment.

Default value: 'mirrored' "mirrored" "mirrored" "mirrored" "mirrored"

Suggested values: 'mirrored'"mirrored""mirrored""mirrored""mirrored", 'cyclic'"cyclic""cyclic""cyclic""cyclic", 'continued'"continued""continued""continued""continued", 0, 30, 60, 90, 120, 150, 180, 210, 240, 255

Example (HDevelop)

read_image (Image, 'fabrik')
draw_region (Region, WindowHandle)
rank_image (Image, Region, ImageRank, 5, 'mirrored')
disp_image (ImageRank, WindowHandle)

Complexity

For each pixel: O(N), where N is the number of runs of MaskMaskMaskMaskmask (see runlength_featuresrunlength_featuresrunlength_featuresRunlengthFeaturesRunlengthFeatures).

Result

If the parameter values are correct the operator rank_imagerank_imagerank_imageRankImageRankImage returns the value 2 (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>)set_system("no_object_result",<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>). If necessary, an exception is raised.

Possible Predecessors

read_imageread_imageread_imageReadImageReadImage, draw_regiondraw_regiondraw_regionDrawRegionDrawRegion, gen_circlegen_circlegen_circleGenCircleGenCircle, gen_rectangle1gen_rectangle1gen_rectangle1GenRectangle1GenRectangle1, gen_rectangle2gen_rectangle2gen_rectangle2GenRectangle2GenRectangle2

Possible Successors

thresholdthresholdthresholdThresholdThreshold, dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold, regiongrowingregiongrowingregiongrowingRegiongrowingRegiongrowing

Alternatives

rank_rectrank_rectrank_rectRankRectRankRect, median_imagemedian_imagemedian_imageMedianImageMedianImage, median_rectmedian_rectmedian_rectMedianRectMedianRect

See also

gray_erosion_rectgray_erosion_rectgray_erosion_rectGrayErosionRectGrayErosionRect, gray_dilation_rectgray_dilation_rectgray_dilation_rectGrayDilationRectGrayDilationRect, gray_erosion_shapegray_erosion_shapegray_erosion_shapeGrayErosionShapeGrayErosionShape, gray_dilation_shapegray_dilation_shapegray_dilation_shapeGrayDilationShapeGrayDilationShape, gray_erosiongray_erosiongray_erosionGrayErosionGrayErosion, gray_dilationgray_dilationgray_dilationGrayDilationGrayDilation

References

T.S. Huang, G.J. Yang, G.Y. Tang; “A Fast Two-Dimensional Median Filtering Algorithm”; IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 27, no. 1, pp. 13-18, 1979.
R. Haralick, L. Shapiro; “Computer and Robot Vision”; Addison-Wesley, 1992, pp. 318-320.

Module

Foundation


Table of Contents / Filters / Smoothing ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH