rank_rectrank_rectRankRectRankRectrank_rect (算子)

名称

rank_rectrank_rectRankRectRankRectrank_rect — 使用矩形掩模计算秩滤波。

签名

rank_rect(Image : ImageRank : MaskWidth, MaskHeight, Rank : )

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)

void RankRect(const HObject& Image, HObject* ImageRank, const HTuple& MaskWidth, const HTuple& MaskHeight, const HTuple& Rank)

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

static void HOperatorSet.RankRect(HObject image, out HObject imageRank, HTuple maskWidth, HTuple maskHeight, HTuple rank)

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

def rank_rect(image: HObject, mask_width: int, mask_height: int, rank: int) -> HObject

描述

rank_rectrank_rectRankRectRankRectRankRectrank_rect performs a rank filter on the input image ImageImageImageImageimageimage with a rectangular mask of size MaskWidthMaskWidthMaskWidthMaskWidthmaskWidthmask_width × MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height and returns the filtered image in ImageRankImageRankImageRankImageRankimageRankimage_rank

Conceptually, the rank filter sorts all gray values within the mask in ascending order and then selects the gray value with rank RankRankRankRankrankrank. The rank 1 corresponds to the smallest gray value and the rank MaskWidthMaskWidthMaskWidthMaskWidthmaskWidthmask_width * MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height corresponds to the largest gray value within the mask. For RankRankRankRankrankrank = (MaskWidthMaskWidthMaskWidthMaskWidthmaskWidthmask_width * MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height - 1) / 2 + 1, rank_rectrank_rectRankRectRankRectRankRectrank_rect returns the median gray value (see median_rectmedian_rectMedianRectMedianRectMedianRectmedian_rect). For RankRankRankRankrankrank = 1, rank_rectrank_rectRankRectRankRectRankRectrank_rect performs a gray value erosion (see gray_erosion_rectgray_erosion_rectGrayErosionRectGrayErosionRectGrayErosionRectgray_erosion_rect, gray_erosion_shapegray_erosion_shapeGrayErosionShapeGrayErosionShapeGrayErosionShapegray_erosion_shape, and gray_erosiongray_erosionGrayErosionGrayErosionGrayErosiongray_erosion), while for RankRankRankRankrankrank = MaskWidthMaskWidthMaskWidthMaskWidthmaskWidthmask_width * MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height rank_rectrank_rectRankRectRankRectRankRectrank_rect performs a gray value dilation (see gray_dilation_rectgray_dilation_rectGrayDilationRectGrayDilationRectGrayDilationRectgray_dilation_rect, gray_dilation_shapegray_dilation_shapeGrayDilationShapeGrayDilationShapeGrayDilationShapegray_dilation_shape, and gray_dilationgray_dilationGrayDilationGrayDilationGrayDilationgray_dilation).

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

有关平滑滤波器概念的说明,请参阅 滤波器 / 平滑 一章的引言。

注意

If even values instead of odd values are passed in MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height or MaskWidthMaskWidthMaskWidthMaskWidthmaskWidthmask_width, rank_rectrank_rectRankRectRankRectRankRectrank_rect uses the next larger odd values instead.

rank_rectrank_rectRankRectRankRectRankRectrank_rect 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_rectrank_rectRankRectRankRectRankRectrank_rect 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_imagerank_imageRankImageRankImageRankImagerank_image is faster than rank_rectrank_rectRankRectRankRectRankRectrank_rect. Typically, this is the case for MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height 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_rectrank_rectRankRectRankRectRankRectrank_rect 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_imageRankImageRankImageRankImagerank_image is faster than rank_rectrank_rectRankRectRankRectRankRectrank_rect even for larger values of MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height

rank_rectrank_rectRankRectRankRectRankRectrank_rect should neither be used with RankRankRankRankrankrank = 1 to perform a gray value erosion nor with RankRankRankRankrankrank = MaskWidthMaskWidthMaskWidthMaskWidthmaskWidthmask_width * MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height to perform a gray value dilation. In these cases, the operators gray_erosion_rectgray_erosion_rectGrayErosionRectGrayErosionRectGrayErosionRectgray_erosion_rect or gray_erosion_shapegray_erosion_shapeGrayErosionShapeGrayErosionShapeGrayErosionShapegray_erosion_shape and gray_dilation_rectgray_dilation_rectGrayDilationRectGrayDilationRectGrayDilationRectgray_dilation_rect or gray_dilation_shapegray_dilation_shapeGrayDilationShapeGrayDilationShapeGrayDilationShapegray_dilation_shape, respectively, are faster than rank_rectrank_rectRankRectRankRectRankRectrank_rect for almost all mask sizes.

请注意,若使用域缩减后的图像作为输入,滤波器算子可能会返回意外结果。请参阅 滤波器 一章

执行信息

参数

ImageImageImageImageimageimage (输入对象)  (multichannel-)image(-array) objectHImageHObjectHImageHobject (byte)

Image to be filtered.

ImageRankImageRankImageRankImageRankimageRankimage_rank (输出对象)  (multichannel-)image(-array) objectHImageHObjectHImageHobject * (byte)

滤波后的图像。

MaskWidthMaskWidthMaskWidthMaskWidthmaskWidthmask_width (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Width of the filter mask.

默认值: 15

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

值范围: 3 ≤ MaskWidth MaskWidth MaskWidth MaskWidth maskWidth mask_width ≤ 4095

最小增量: 2

建议增量: 2

MaskHeightMaskHeightMaskHeightMaskHeightmaskHeightmask_height (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Height of the filter mask.

默认值: 15

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

值范围: 3 ≤ MaskHeight MaskHeight MaskHeight MaskHeight maskHeight mask_height ≤ 4095

最小增量: 2

建议增量: 2

RankRankRankRankrankrank (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Rank of the output gray value.

默认值: 5

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

最小增量: 1

建议增量: 2

限制: 1 <= Rank && Rank <= MaskWidth * MaskHeight

复杂度

对于每个像素:O(1)。

结果

如果参数值正确,算子 rank_rectrank_rectRankRectRankRectRankRectrank_rect 返回值 2 ( H_MSG_TRUE )。 The behavior in case of empty input (no input images available) is set via set_system('no_object_result',<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>)set_system("no_object_result",<Result>)。如有必要,则抛出异常。

可能的前趋

read_imageread_imageReadImageReadImageReadImageread_image

可能的后继

thresholdthresholdThresholdThresholdThresholdthreshold, dyn_thresholddyn_thresholdDynThresholdDynThresholdDynThresholddyn_threshold, regiongrowingregiongrowingRegiongrowingRegiongrowingRegiongrowingregiongrowing

替代

rank_imagerank_imageRankImageRankImageRankImagerank_image, median_rectmedian_rectMedianRectMedianRectMedianRectmedian_rect, median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image

另见

gray_erosion_rectgray_erosion_rectGrayErosionRectGrayErosionRectGrayErosionRectgray_erosion_rect, gray_dilation_rectgray_dilation_rectGrayDilationRectGrayDilationRectGrayDilationRectgray_dilation_rect, gray_erosion_shapegray_erosion_shapeGrayErosionShapeGrayErosionShapeGrayErosionShapegray_erosion_shape, gray_dilation_shapegray_dilation_shapeGrayDilationShapeGrayDilationShapeGrayDilationShapegray_dilation_shape, gray_erosiongray_erosionGrayErosionGrayErosionGrayErosiongray_erosion, gray_dilationgray_dilationGrayDilationGrayDilationGrayDilationgray_dilation

参考文献

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.

模块

基础