rank_imagerank_imageRankImageRankImagerank_image (算子)

名称

rank_imagerank_imageRankImageRankImagerank_image — 使用任意掩模计算秩滤波。

签名

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)

void RankImage(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)

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)

def rank_image(image: HObject, mask: HObject, rank: int, margin: Union[int, float, str]) -> HObject

描述

rank_imagerank_imageRankImageRankImageRankImagerank_image performs a rank filter on the input image ImageImageImageImageimageimage with a mask that is specified by the region MaskMaskMaskMaskmaskmask and returns the filtered image in ImageRankImageRankImageRankImageRankimageRankimage_rank. The shape of the mask can be chosen arbitrarily and can, for example, be created with operators like gen_circlegen_circleGenCircleGenCircleGenCirclegen_circle or draw_regiondraw_regionDrawRegionDrawRegionDrawRegiondraw_region。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 RankRankRankRankrankrank. 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 MaskMaskMaskMaskmaskmask (see area_centerarea_centerAreaCenterAreaCenterAreaCenterarea_center). For RankRankRankRankrankrank = (A - 1) / 2 + 1, rank_imagerank_imageRankImageRankImageRankImagerank_image returns the median gray value (see median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image). For RankRankRankRankrankrank = 1, rank_imagerank_imageRankImageRankImageRankImagerank_image 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 = A rank_imagerank_imageRankImageRankImageRankImagerank_image 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_imagerank_imageRankImageRankImageRankImagerank_image can be used, for example, to suppress noise or to suppress unwanted objects that are smaller than the mask. Furthermore, rank_imagerank_imageRankImageRankImageRankImagerank_image 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 RankRankRankRankrankrank

Several border treatments can be chosen for filtering via the parameter MarginMarginMarginMarginmarginmargin: 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.

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

注意

rank_imagerank_imageRankImageRankImageRankImagerank_image uses an algorithm with a runtime per pixel that depends on the number of runs in the mask MaskMaskMaskMaskmaskmask. Therefore, rank_imagerank_imageRankImageRankImageRankImagerank_image is slower than rank_rectrank_rectRankRectRankRectRankRectrank_rect for rectangular masks with a large mask height. The precise mask height for which rank_rectrank_rectRankRectRankRectRankRectrank_rect will become faster than rank_imagerank_imageRankImageRankImageRankImagerank_image 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_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 mask heights.

rank_imagerank_imageRankImageRankImageRankImagerank_image should neither be used with RankRankRankRankrankrank = 1 to perform a gray value erosion nor with RankRankRankRankrankrank = A to perform a gray value dilation. In these cases, the operators gray_erosion_rectgray_erosion_rectGrayErosionRectGrayErosionRectGrayErosionRectgray_erosion_rect, gray_erosion_shapegray_erosion_shapeGrayErosionShapeGrayErosionShapeGrayErosionShapegray_erosion_shape, or gray_erosiongray_erosionGrayErosionGrayErosionGrayErosiongray_erosion and gray_dilation_rectgray_dilation_rectGrayDilationRectGrayDilationRectGrayDilationRectgray_dilation_rect, gray_dilation_shapegray_dilation_shapeGrayDilationShapeGrayDilationShapeGrayDilationShapegray_dilation_shape, or gray_dilationgray_dilationGrayDilationGrayDilationGrayDilationgray_dilation, respectively, are typically faster than rank_imagerank_imageRankImageRankImageRankImagerank_image.

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

执行信息

参数

ImageImageImageImageimageimage (输入对象)  (multichannel-)image(-array) objectHImageHObjectHImageHobject (byte / int2 / uint2 / int4 / real)

Image to be filtered.

MaskMaskMaskMaskmaskmask (输入对象)  region objectHRegionHObjectHRegionHobject

Filter mask.

ImageRankImageRankImageRankImageRankimageRankimage_rank (输出对象)  multichannel-image(-array) objectHImageHObjectHImageHobject * (byte / int2 / uint2 / int4 / real)

滤波后的图像。

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 ≤ Rank Rank Rank Rank rank rank ≤ 4095

最小增量: 1

建议增量: 2

MarginMarginMarginMarginmarginmargin (输入控制)  string HTupleUnion[int, float, str]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)

Border treatment.

默认值: 'mirrored' "mirrored" "mirrored" "mirrored" "mirrored" "mirrored"

建议值: 'mirrored'"mirrored""mirrored""mirrored""mirrored""mirrored", 'cyclic'"cyclic""cyclic""cyclic""cyclic""cyclic", 'continued'"continued""continued""continued""continued""continued", 0, 30, 60, 90, 120, 150, 180, 210, 240, 255

示例(HDevelop)

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

复杂度

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

结果

如果参数值正确,算子 rank_imagerank_imageRankImageRankImageRankImagerank_image 返回值 2 ( H_MSG_TRUE )。当输入为空(无可用输入图像)时可设置行为通过算子 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, draw_regiondraw_regionDrawRegionDrawRegionDrawRegiondraw_region, gen_circlegen_circleGenCircleGenCircleGenCirclegen_circle, gen_rectangle1gen_rectangle1GenRectangle1GenRectangle1GenRectangle1gen_rectangle1, gen_rectangle2gen_rectangle2GenRectangle2GenRectangle2GenRectangle2gen_rectangle2

可能的后继

thresholdthresholdThresholdThresholdThresholdthreshold, dyn_thresholddyn_thresholdDynThresholdDynThresholdDynThresholddyn_threshold, regiongrowingregiongrowingRegiongrowingRegiongrowingRegiongrowingregiongrowing

替代

rank_rectrank_rectRankRectRankRectRankRectrank_rect, median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image, median_rectmedian_rectMedianRectMedianRectMedianRectmedian_rect

另见

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

参考文献

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.

模块

基础