Skip to content

rank_rectRankRectRankRectrank_rectrank_rectπŸ”—

Short descriptionπŸ”—

rank_rectRankRectRankRectrank_rectrank_rect β€” Compute a rank filter with rectangular masks.

SignatureπŸ”—

rank_rect( image Image, out image ImageRank, integer MaskWidth, integer MaskHeight, integer Rank )void RankRect( const HObject& Image, HObject* ImageRank, const HTuple& MaskWidth, const HTuple& MaskHeight, const HTuple& Rank )static void HOperatorSet.RankRect( HObject image, out HObject imageRank, HTuple maskWidth, HTuple maskHeight, HTuple rank )def rank_rect( image: HObject, mask_width: int, mask_height: int, rank: int ) -> HObject

Herror rank_rect( const Hobject Image, Hobject* ImageRank, const Hlong MaskWidth, const Hlong MaskHeight, const Hlong Rank )

Herror T_rank_rect( const Hobject Image, Hobject* ImageRank, const Htuple MaskWidth, const Htuple MaskHeight, const Htuple Rank )

HImage HImage::RankRect( Hlong MaskWidth, Hlong MaskHeight, Hlong Rank ) const

HImage HImage.RankRect( int maskWidth, int maskHeight, int rank )

DescriptionπŸ”—

rank_rectRankRect performs a rank filter on the input image Imageimageimage with a rectangular mask of size MaskWidthmaskWidthmask_width Γ— MaskHeightmaskHeightmask_height and returns the filtered image in ImageRankimageRankimage_rank.

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 MaskWidth * MaskHeight corresponds to the largest gray value within the mask. For Rank = (MaskWidth * MaskHeight - 1) / 2 + 1, rank_rectRankRect returns the median gray value (see median_rectMedianRect). For Rank = 1, rank_rectRankRect performs a gray value erosion (see gray_erosion_rectGrayErosionRect, gray_erosion_shapeGrayErosionShape, and gray_erosionGrayErosion), while for Rank = MaskWidth * MaskHeight rank_rectRankRect performs a gray value dilation (see gray_dilation_rectGrayDilationRect, gray_dilation_shapeGrayDilationShape, and gray_dilationGrayDilation).

rank_rectRankRect can be used, for example, to suppress noise or to suppress unwanted objects that are smaller than the mask. Furthermore, rank_rectRankRect 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 MaskWidth * MaskHeight, slightly larger or smaller values should be selected for Rankrankrank.

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

AttentionπŸ”—

If even values instead of odd values are passed in MaskHeightmaskHeightmask_height or MaskWidthmaskWidthmask_width, rank_rectRankRect uses the next larger odd values instead.

rank_rectRankRect uses an algorithm with constant runtime per pixel, i.e., the runtime only depends on the size of the input image and not on the mask size. Therefore, for large mask sizes rank_rectRankRect is the fastest implementation of the rank filter in HALCON. Depending on the computer architecture (processor type, availability of SIMD instructions like SSE2 or MMX, cache size and throughput, memory throughput), for small mask sizes the implementation used in rank_imageRankImage is faster than rank_rectRankRect. Typically, this is the case for MaskHeightmaskHeightmask_height \(\le\) 15, but can also happen 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 values of MaskHeightmaskHeightmask_height.

rank_rectRankRect should neither be used with Rank = 1 to perform a gray value erosion nor with Rank = MaskWidth * MaskHeight to perform a gray value dilation. In these cases, the operators gray_erosion_rectGrayErosionRect or gray_erosion_shapeGrayErosionShape and gray_dilation_rectGrayDilationRect or gray_dilation_shapeGrayDilationShape, respectively, are faster than rank_rectRankRect for almost all mask sizes.

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 tuple level.

  • Automatically parallelized on channel level.

  • Automatically parallelized on domain level.

ParametersπŸ”—

Imageimageimage (input_object) (multichannel-)image(-array) β†’ object (byte)HObject (byte)HImage (byte)HObject (byte)Hobject (byte)

Image to be filtered.

ImageRankimageRankimage_rank (output_object) (multichannel-)image(-array) β†’ object (byte)HObject (byte)HImage (byte)HObject (byte)Hobject * (byte)

Filtered image.

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

Width of the filter mask.

Default: 1515
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: 3 ≀ MaskWidth ≀ 4095
Minimum increment: 2
Recommended increment: 2

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

Height of the filter mask.

Default: 1515
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: 3 ≀ MaskHeight ≀ 4095
Minimum increment: 2
Recommended increment: 2

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
Minimum increment: 1
Recommended increment: 2
Restriction: 1 <= Rank && Rank <= MaskWidth*MaskHeight

ComplexityπŸ”—

For each pixel: \(O(1)\).

ResultπŸ”—

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

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

read_imageReadImage

Possible successors

thresholdThreshold, dyn_thresholdDynThreshold, regiongrowingRegiongrowing

Alternatives

rank_imageRankImage, median_rectMedianRect, median_imageMedianImage

See also

gray_erosion_rectGrayErosionRect, gray_dilation_rectGrayDilationRect, gray_erosion_shapeGrayErosionShape, gray_dilation_shapeGrayDilationShape, gray_erosionGrayErosion, gray_dilationGrayDilation

ReferencesπŸ”—

S. Perreault, P. HΓ©bert; β€œMedian Filtering in Constant Time”; IEEE Transactions on Image Processing, vol.Β 16, no.Β 9, pp.Β 2389-2394, 2007.

D. Cline, K.B. White, P.K. Egbert; ``Fast 8-Bit Median Filtering Based On Separabilityβ€™β€˜; International Conference on Image Processing, vol. V, pp. 281-284, 2007.

ModuleπŸ”—

Foundation