median_imagemedian_imageMedianImageMedianImagemedian_image (算子)

名称

median_imagemedian_imageMedianImageMedianImagemedian_image — 使用各种掩模计算中值滤波器。

签名

median_image(Image : ImageMedian : MaskType, Radius, Margin : )

Herror median_image(const Hobject Image, Hobject* ImageMedian, const char* MaskType, const Hlong Radius, const char* Margin)

Herror T_median_image(const Hobject Image, Hobject* ImageMedian, const Htuple MaskType, const Htuple Radius, const Htuple Margin)

void MedianImage(const HObject& Image, HObject* ImageMedian, const HTuple& MaskType, const HTuple& Radius, const HTuple& Margin)

HImage HImage::MedianImage(const HString& MaskType, Hlong Radius, const HTuple& Margin) const

HImage HImage::MedianImage(const HString& MaskType, Hlong Radius, const HString& Margin) const

HImage HImage::MedianImage(const char* MaskType, Hlong Radius, const char* Margin) const

HImage HImage::MedianImage(const wchar_t* MaskType, Hlong Radius, const wchar_t* Margin) const   ( Windows only)

static void HOperatorSet.MedianImage(HObject image, out HObject imageMedian, HTuple maskType, HTuple radius, HTuple margin)

HImage HImage.MedianImage(string maskType, int radius, HTuple margin)

HImage HImage.MedianImage(string maskType, int radius, string margin)

def median_image(image: HObject, mask_type: str, radius: int, margin: Union[int, float, str]) -> HObject

描述

median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image performs a median filter on the input image ImageImageImageImageimageimage with a square or circular mask and returns the filtered image in ImageMedianImageMedianImageMedianImageMedianimageMedianimage_median. The shape of the mask can be selected with MaskTypeMaskTypeMaskTypeMaskTypemaskTypemask_type. The radius of the mask can be selected with RadiusRadiusRadiusRadiusradiusradius

Conceptually, the median filter sorts all gray values within the mask in ascending order and then selects the median of the gray values. The median is the “middle” one of the sorted gray values, i.e., the gray value with rank (position) (N - 1) / 2 + 1 of the sorted gray values, where N denotes the number of pixels covered by the filter mask. Here, the rank 1 corresponds to the smallest gray value and the rank N corresponds to the largest gray value within the mask (see also rank_imagerank_imageRankImageRankImageRankImagerank_image).

The filter mask is determined by RadiusRadiusRadiusRadiusradiusradius, defining the size, and MaskTypeMaskTypeMaskTypeMaskTypemaskTypemask_type, defining the shape of the mask. For latter one, the following options are available:

median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image can be used, for example, to smooth images, to suppress unwanted objects (e.g., point-like or line-like structures) that are smaller than the mask, and can therefore be used to estimate the background illumination for a shading correction or as a preprocessing step for the dynamic threshold operation (see dyn_thresholddyn_thresholdDynThresholdDynThresholdDynThresholddyn_threshold).

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

When using the MaskTypeMaskTypeMaskTypeMaskTypemaskTypemask_type 'square'"square""square""square""square""square" with RadiusRadiusRadiusRadiusradiusradius 1 or 2 (resulting in a 3x3 or 5x5 pixel filter mask) and the border treatment 'mirrored', median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image 可在 OpenCL 设备上执行。

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

注意

median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image uses an algorithm with a runtime per pixel that depends on the mask height 2 * RadiusRadiusRadiusRadiusradiusradius + 1. Therefore, median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image is slower than median_rectmedian_rectMedianRectMedianRectMedianRectmedian_rect for square masks with a large mask height. The precise mask height for which median_rectmedian_rectMedianRectMedianRectMedianRectmedian_rect will become faster than median_imagemedian_imageMedianImageMedianImageMedianImagemedian_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 median_rectmedian_rectMedianRectMedianRectMedianRectmedian_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 median_imagemedian_imageMedianImageMedianImageMedianImagemedian_image is faster than median_rectmedian_rectMedianRectMedianRectMedianRectmedian_rect even for larger mask heights.

Due to performance reasons, the input ImageImageImageImageimageimage is not checked whether it contains NaNs. Using an input image with NaNs crashes HALCON.

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

执行信息

参数

ImageImageImageImageimageimage (输入对象)  (multichannel-)image(-array) objectHImageHObjectHImageHobject (byte* / int2* / uint2* / int4* / real*) *允许用于计算设备

Image to be filtered.

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

滤波后的图像。

MaskTypeMaskTypeMaskTypeMaskTypemaskTypemask_type (输入控制)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Filter mask type.

默认值: 'circle' "circle" "circle" "circle" "circle" "circle"

值列表: 'circle'"circle""circle""circle""circle""circle", 'square'"square""square""square""square""square"

List of values (for compute devices): 'square'"square""square""square""square""square"

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

Radius of the filter mask.

默认值: 1

List of values (for compute devices): 1, 2

建议值: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 15, 19, 25, 31, 39, 47, 59

值范围: 1 ≤ Radius Radius Radius Radius radius radius ≤ 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"

List of values (for compute devices): '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')
median_image (Image, Median, 'circle', 3, 'continued')
dev_display(Median)

复杂度

For each pixel: O(2 * RadiusRadiusRadiusRadiusradiusradius + 1).

结果

如果参数值正确,算子 median_imagemedian_imageMedianImageMedianImageMedianImagemedian_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

可能的后继

thresholdthresholdThresholdThresholdThresholdthreshold, dyn_thresholddyn_thresholdDynThresholdDynThresholdDynThresholddyn_threshold, regiongrowingregiongrowingRegiongrowingRegiongrowingRegiongrowingregiongrowing

替代

median_rectmedian_rectMedianRectMedianRectMedianRectmedian_rect, rank_imagerank_imageRankImageRankImageRankImagerank_image, rank_rectrank_rectRankRectRankRectRankRectrank_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.

模块

基础