Skip to content

rank_imageRankImageRankImagerank_imagerank_imageπŸ”—

Short descriptionπŸ”—

rank_imageRankImageRankImagerank_imagerank_image β€” Compute a rank filter with arbitrary masks.

SignatureπŸ”—

rank_image( image Image, region Mask, out image ImageRank, integer Rank, string Margin )void RankImage( const HObject& Image, const HObject& Mask, HObject* ImageRank, const HTuple& Rank, const HTuple& Margin )static void HOperatorSet.RankImage( HObject image, HObject mask, out HObject imageRank, HTuple rank, HTuple margin )def rank_image( image: HObject, mask: HObject, rank: int, margin: Union[int, float, str] ) -> HObject

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 )

HImage HImage::RankImage( const HRegion& Mask, Hlong Rank, const HTuple& Margin ) const

HImage HImage::RankImage( const HRegion& Mask, Hlong Rank, const HString& Margin ) const

HImage HImage::RankImage( const HRegion& Mask, Hlong Rank, const char* Margin ) const

HImage HImage::RankImage( const HRegion& Mask, Hlong Rank, const wchar_t* Margin ) const (Windows only)

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

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

DescriptionπŸ”—

rank_imageRankImage performs a rank filter on the input image Imageimageimage with a mask that is specified by the region Maskmaskmask and returns the filtered image in ImageRankimageRankimage_rank. The shape of the mask can be chosen arbitrarily and can, for example, be created with operators like gen_circleGenCircle or draw_regionDrawRegion. 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 Rankrankrank. 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 Maskmaskmask (see area_centerAreaCenter). For \(\textrm{Rank} = (A - 1) / 2 + 1\), rank_imageRankImage returns the median gray value (see median_imageMedianImage). For \(\textrm{Rank} = 1\), rank_imageRankImage performs a gray value erosion (see gray_erosion_rectGrayErosionRect, gray_erosion_shapeGrayErosionShape, and gray_erosionGrayErosion), while for \(\textrm{Rank} = A\) rank_imageRankImage performs a gray value dilation (see gray_dilation_rectGrayDilationRect, gray_dilation_shapeGrayDilationShape, and gray_dilationGrayDilation).

rank_imageRankImage can be used, for example, to suppress noise or to suppress unwanted objects that are smaller than the mask. Furthermore, rank_imageRankImage is less sensitive to noise than the corresponding 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 Rankrankrank.

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

  • gray value Pixels outside of the image border are assumed to be constant (with the indicated gray value).

  • 'continued'"continued" Continuation of the gray values at the image border.

  • 'cyclic'"cyclic" Cyclic continuation at the image borders.

  • 'mirrored'"mirrored" Reflection of pixels at the image borders.

For an explanation of the concept of smoothing filters see the introduction of chapter Filters / Smoothing.

AttentionπŸ”—

rank_imageRankImage uses an algorithm with a runtime per pixel that depends on the number of runs in the mask Maskmaskmask. Therefore, rank_imageRankImage is slower than rank_rectRankRect for rectangular masks with a large mask height. The precise mask height for which rank_rectRankRect will become faster than rank_imageRankImage 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_rectRankRect 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_imageRankImage is faster than rank_rectRankRect even for larger mask heights.

rank_imageRankImage should neither be used with \(\textrm{Rank} = 1\) to perform a gray value erosion nor with \(\textrm{Rank} = A\) to perform a gray value dilation. In these cases, the operators gray_erosion_rectGrayErosionRect, gray_erosion_shapeGrayErosionShape, or gray_erosionGrayErosion and gray_dilation_rectGrayDilationRect, gray_dilation_shapeGrayDilationShape, or gray_dilationGrayDilation, respectively, are typically faster than rank_imageRankImage.

Note that filter operators may return unexpected results if an image with a reduced domain is used as input. Please refer to the chapter Filters.

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on domain level.

ParametersπŸ”—

Imageimageimage (input_object) (multichannel-)image(-array) β†’ object (byte / int2 / uint2 / int4 / real)HObject (byte / int2 / uint2 / int4 / real)HImage (byte / int2 / uint2 / int4 / real)HObject (byte / int2 / uint2 / int4 / real)Hobject (byte / int2 / uint2 / int4 / real)

Image to be filtered.

Maskmaskmask (input_object) region β†’ objectHObjectHRegionHObjectHobject

Filter mask.

ImageRankimageRankimage_rank (output_object) multichannel-image(-array) β†’ object (byte / int2 / uint2 / int4 / real)HObject (byte / int2 / uint2 / int4 / real)HImage (byte / int2 / uint2 / int4 / real)HObject (byte / int2 / uint2 / int4 / real)Hobject * (byte / int2 / uint2 / int4 / real)

Filtered image.

Rankrankrank (input_control) integer β†’ (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Rank of the output gray value.

Default: 55
Suggested values: 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 31, 49, 51, 61, 71, 81, 91, 1013, 5, 7, 9, 11, 13, 15, 17, 19, 21, 31, 49, 51, 61, 71, 81, 91, 101
Value range: 1 ≀ Rank ≀ 4095
Minimum increment: 1
Recommended increment: 2

Marginmarginmargin (input_control) string β†’ (string / integer / real)HTuple (HString / Hlong / double)HTuple (string / int / long / double)Union[int, float, str]Htuple (char* / Hlong / double)

Border treatment.

Default: 'mirrored'"mirrored"
Suggested values: 'mirrored', 'cyclic', 'continued', 0, 30, 60, 90, 120, 150, 180, 210, 240, 255"mirrored", "cyclic", "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')
dev_display(ImageRank)

ComplexityπŸ”—

For each pixel: \(O(N)\), where \(N\) is the number of runs of Maskmaskmask (see runlength_featuresRunlengthFeatures).

ResultπŸ”—

If the parameter values are correct the operator rank_imageRankImage 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>). If necessary, an exception is raised.

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

read_imageReadImage, draw_regionDrawRegion, gen_circleGenCircle, gen_rectangle1GenRectangle1, gen_rectangle2GenRectangle2

Possible successors

thresholdThreshold, dyn_thresholdDynThreshold, regiongrowingRegiongrowing

Alternatives

rank_rectRankRect, median_imageMedianImage, median_rectMedianRect

See also

gray_erosion_rectGrayErosionRect, gray_dilation_rectGrayDilationRect, gray_erosion_shapeGrayErosionShape, gray_dilation_shapeGrayDilationShape, gray_erosionGrayErosion, gray_dilationGrayDilation

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