Skip to content

trimmed_meantrimmed_meanTrimmedMeanTrimmedMeantrimmed_meantrimmed_meanπŸ”—

Short descriptionπŸ”—

trimmed_meantrimmed_meanTrimmedMeanTrimmedMeantrimmed_meantrimmed_mean β€” Smooth an image with an arbitrary rank mask.

SignatureπŸ”—

trimmed_mean( image Image, region Mask, out image ImageTMean, integer Number, string Margin )trimmed_mean( Image, Mask : ImageTMean : Number, Margin : )void TrimmedMean( const HObject& Image, const HObject& Mask, HObject* ImageTMean, const HTuple& Number, const HTuple& Margin )static void HOperatorSet.TrimmedMean( HObject image, HObject mask, out HObject imageTMean, HTuple number, HTuple margin )def trimmed_mean( image: HObject, mask: HObject, number: int, margin: Union[int, float, str] ) -> HObject

Herror trimmed_mean( const Hobject Image, const Hobject Mask, Hobject* ImageTMean, const Hlong Number, const char* Margin )

Herror T_trimmed_mean( const Hobject Image, const Hobject Mask, Hobject* ImageTMean, const Htuple Number, const Htuple Margin )

HImage HImage::TrimmedMean( const HRegion& Mask, Hlong Number, const HTuple& Margin ) const

HImage HImage::TrimmedMean( const HRegion& Mask, Hlong Number, const HString& Margin ) const

HImage HImage::TrimmedMean( const HRegion& Mask, Hlong Number, const char* Margin ) const

HImage HImage::TrimmedMean( const HRegion& Mask, Hlong Number, const wchar_t* Margin ) const (Windows only)

HImage HImage.TrimmedMean( HRegion mask, int number, HTuple margin )

HImage HImage.TrimmedMean( HRegion mask, int number, string margin )

DescriptionπŸ”—

The operator trimmed_meanTrimmedMean carries out a non-linear smoothing of the gray values of all input images (Imageimageimage). The filter mask (Maskmaskmask) is passed in the form of a region. The average of Numbernumbernumber gray values located near the median is calculated. Several border treatments can be chosen for filtering (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.

The indicated mask (= region of the mask image) is put over the image to be filtered in such a way that the center of the mask touches all pixels once. For each of these pixels all neighboring pixels covered by the mask are sorted in an ascending sequence according to their gray values. Thus, each of these sorted gray value sequences contains exactly as many gray values as the mask has pixels. If F is the area of the mask the average of these sequences is calculated as follows: The first (F - Number)/2 gray values are ignored. Then the following Numbernumbernumber gray values are summed up and divided by Numbernumbernumber. Again the remaining (F - Numbernumbernumber)/2 gray values are ignored.

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

AttentionπŸ”—

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

  • Automatically parallelized on domain level.

ParametersπŸ”—

Imageimageimage (input_object) (multichannel-)image(-array) β†’ object (byte / int2 / uint2 / int4 / real)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 β†’ objectobjectHObjectHRegionHObjectHobject

Image whose region serves as filter mask.

ImageTMeanimageTMeanimage_tmean (output_object) (multichannel-)image(-array) β†’ object (byte / int2 / uint2 / int4 / real)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 output image.

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

Number of averaged pixels. Typical value: Surface(Mask) / 2.

Default: 55
Suggested values: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 311, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31
Value range: 1 ≀ Number ≀ 401
Minimum increment: 1
Recommended increment: 2

Marginmarginmargin (input_control) string β†’ (string / integer / real)(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)
trimmed_mean(Image,Region,TrimmedMean,5,'mirrored')
dev_display(TrimmedMean)
(C)
read_image(&Image,"fabrik")\;
draw_region(&Region,WindowHandle)\;
trimmed_mean(Image,Region,&TrimmedMean,5,"mirrored")\;
disp_image(TrimmedMean,WindowHandle)\;

ResultπŸ”—

If the parameter values are correct the operator trimmed_meanTrimmedMean 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

Possible successors

thresholdThreshold, dyn_thresholdDynThreshold, regiongrowingRegiongrowing

Alternatives

sigma_imageSigmaImage, median_weightedMedianWeighted, median_imageMedianImage

See also

gen_circleGenCircle, gen_rectangle1GenRectangle1, gray_erosion_rectGrayErosionRect, gray_dilation_rectGrayDilationRect

ReferencesπŸ”—

R. Haralick, L. Shapiro; β€œComputer and Robot Vision”; Addison-Wesley, 1992, Seite 320

ModuleπŸ”—

Foundation