ClassesClassesClassesClasses | | | | Operators

guided_filterguided_filterGuidedFilterguided_filterGuidedFilterGuidedFilter (Operator)


guided_filterguided_filterGuidedFilterguided_filterGuidedFilterGuidedFilter — Guided filtering of an image.


guided_filter(Image, ImageGuide : ImageGuided : Radius, Amplitude : )

Herror guided_filter(const Hobject Image, const Hobject ImageGuide, Hobject* ImageGuided, const Hlong Radius, double Amplitude)

Herror T_guided_filter(const Hobject Image, const Hobject ImageGuide, Hobject* ImageGuided, const Htuple Radius, const Htuple Amplitude)

Herror guided_filter(Hobject Image, Hobject ImageGuide, Hobject* ImageGuided, const HTuple& Radius, const HTuple& Amplitude)

HImage HImage::GuidedFilter(const HImage& ImageGuide, const HTuple& Radius, const HTuple& Amplitude) const

HImageArray HImageArray::GuidedFilter(const HImageArray& ImageGuide, const HTuple& Radius, const HTuple& Amplitude) const

void GuidedFilter(const HObject& Image, const HObject& ImageGuide, HObject* ImageGuided, const HTuple& Radius, const HTuple& Amplitude)

HImage HImage::GuidedFilter(const HImage& ImageGuide, Hlong Radius, double Amplitude) const

void HOperatorSetX.GuidedFilter(
[in] IHUntypedObjectX* Image, [in] IHUntypedObjectX* ImageGuide, [out] IHUntypedObjectX*ImageGuided, [in] VARIANT Radius, [in] VARIANT Amplitude)

IHImageX* HImageX.GuidedFilter(
[in] IHImageX* ImageGuide, [in] Hlong Radius, [in] double Amplitude)

static void HOperatorSet.GuidedFilter(HObject image, HObject imageGuide, out HObject imageGuided, HTuple radius, HTuple amplitude)

HImage HImage.GuidedFilter(HImage imageGuide, int radius, double amplitude)


guided_filterguided_filterGuidedFilterguided_filterGuidedFilterGuidedFilter filters the input ImageImageImageImageImageimage using the guidance image ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide and returns the result in ImageGuidedImageGuidedImageGuidedImageGuidedImageGuidedimageGuided. ImageImageImageImageImageimage and ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide must be of the same size and type.

The RadiusRadiusRadiusRadiusRadiusradius is the size of the filter mask. Bigger values increase the area of influence of the filter and less detail is preserved. The value of RadiusRadiusRadiusRadiusRadiusradius does not influence the runtime of the operator.

AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude is used to decide what is an edge and what is a homogeneous area. Bigger values of AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude lead to stronger edges being smoothed. As a rule of thumb, AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude should be lower than the contrast of the edges that should be preserved. Please note that the contrast in uint2 or real images may differ significantly from the default values of AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude and adjust the parameter accordingly.

Influence of the Guidance Image

If ImageImageImageImageImageimage and ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide are identical, guided_filterguided_filterGuidedFilterguided_filterGuidedFilterGuidedFilter behaves like an edge-preserving smoothing with a filter mask with RadiusRadiusRadiusRadiusRadiusradius. Pixels at edges that have a contrast significantly greater than AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude are preserved, while pixels in homogeneous areas are smoothed. Hence, guided_filterguided_filterGuidedFilterguided_filterGuidedFilterGuidedFilter is a fast alternative to anisotropic_diffusionanisotropic_diffusionAnisotropicDiffusionanisotropic_diffusionAnisotropicDiffusionAnisotropicDiffusion or bilateral_filterbilateral_filterBilateralFilterbilateral_filterBilateralFilterBilateralFilter.

(1) (2) (3)
(1) ImageImageImageImageImageimage and (2) ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide are identical. That leads to edge-preserving smoothing in (3) ImageGuidedImageGuidedImageGuidedImageGuidedImageGuidedimageGuided.

If ImageImageImageImageImageimage and ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide are different, ImageImageImageImageImageimage is smoothed with a filter mask with RadiusRadiusRadiusRadiusRadiusradius, except in areas where ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide has edges with a contrast significantly greater than AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude.

(1) (2) (3)
(1) ImageImageImageImageImageimage and (2) ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide are different. (3) ImageGuidedImageGuidedImageGuidedImageGuidedImageGuidedimageGuided: Only edges are preserved where ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide has edges.

If ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide is constant, guided_filterguided_filterGuidedFilterguided_filterGuidedFilterGuidedFilter is equivalent to 2 consecutive calls of mean_imagemean_imageMeanImagemean_imageMeanImageMeanImage with mask size 2*RadiusRadiusRadiusRadiusRadiusradius+1.

(1) (2) (3)
(2) ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide is constant. This is equivalent to a double smoothing of (1) ImageImageImageImageImageimage with mean_imagemean_imageMeanImagemean_imageMeanImageMeanImage. (3) ImageGuidedImageGuidedImageGuidedImageGuidedImageGuidedimageGuided

Influence of the smoothing parameters

The following examples show the influence of AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude on an artificial image. In this image, the noise level is 10 gray values, the left edge has a contrast of 50 gray values, the right edge has a contrast of 100 gray values. The yellow line shows a gray-value profile of a horizontal cross section.

Original image with overlaid gray profile, used as ImageImageImageImageImageimage and ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide.
Filter result with AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude = 1: No effect because AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude is below noise level. Therefore noise is treated as edge and preserved.
Filter result with AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude = 25: Noise is smoothed, edges are preserved.
Filter result with AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude = 50: The weaker edge is smoothed, the stronger edge is preserved.
Filter result with AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude = 100: Both edges are smoothed.

Rolling Guided Filter

guided_filterguided_filterGuidedFilterguided_filterGuidedFilterGuidedFilter can be applied iteratively. In this case, the result of one iteration is used as guidance image for the next iteration. This can be useful, e.g., to remove small structures from the original image even if they have a high contrast.

In the following example, the rolling guided filter is used to separate the texture from the original image.

(1) (2) (3)
Texture removal with the rolling guided filter: (1) Original, (2) separated structure, (3) separated texture.

  * Apply the rolling guided filter
  * (use a constant guide for the first iteration).
  gen_image_proto (Image, ImageStructure, 0)
  for I := 1 to 4 by 1
    guided_filter (Image, ImageStructure, ImageStructure, 1.5, 60)
  * Separate texture by subtracting large structures from the original.
  sub_image (Image, ImageStructure, ImageTexture, 1, 128)

Since guided_filterguided_filterGuidedFilterguided_filterGuidedFilterGuidedFilter with a constant ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide is similar to mean_imagemean_imageMeanImagemean_imageMeanImageMeanImage, the first iteration could be replaced by a call of mean_imagemean_imageMeanImagemean_imageMeanImageMeanImage (or a similar smoothing filter), which is faster.

Mathematical Background

The calculation of the filtered gray value at the position is done according to the following formula:

where and are the gray values of ImageImageImageImageImageimage and ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide at the pixel position , is the neighborhood with radius RadiusRadiusRadiusRadiusRadiusradius around the pixel , , , , and are the mean of all , , , or in , is the standard deviation of all gray values of in , and is the number of pixels in .



ImageImageImageImageImageimage (input_object)  (multichannel-)image(-array) objectHImageHImageHImageHImageXHobject (byte / uint2 / real)

Input image.

ImageGuideImageGuideImageGuideImageGuideImageGuideimageGuide (input_object)  (multichannel-)image(-array) objectHImageHImageHImageHImageXHobject (byte / uint2 / real)

Guidance image.

ImageGuidedImageGuidedImageGuidedImageGuidedImageGuidedimageGuided (output_object)  (multichannel-)image(-array) objectHImageHImageHImageHImageXHobject * (byte / uint2 / real)

Output image.

RadiusRadiusRadiusRadiusRadiusradius (input_control)  integer HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Radius of the filtering operation.

Default value: 3

Suggested values: 1, 2, 3, 5, 10

Restriction: Radius > 0

AmplitudeAmplitudeAmplitudeAmplitudeAmplitudeamplitude (input_control)  real HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (double)

Controls the influence of edges on the smoothing.

Default value: 20.0

Suggested values: 3.0, 10.0, 20.0, 50.0, 100.0

Restriction: Amplitude > 0

Example (HDevelop)

read_image (Image, 'mreut')
* Edge-preserving smoothing
guided_filter (Image, Image, ImageGuided, 5, 20)
* Rolling filter (5 iterations)
gen_image_proto (Image, ImageGuide, 0)
for I := 1 to 5 by 1
  guided_filter (Image, ImageGuide, ImageGuide, 5, 20)

Possible Predecessors


Possible Successors

thresholdthresholdThresholdthresholdThresholdThreshold, dyn_thresholddyn_thresholdDynThresholddyn_thresholdDynThresholdDynThreshold, regiongrowingregiongrowingRegiongrowingregiongrowingRegiongrowingRegiongrowing


bilateral_filterbilateral_filterBilateralFilterbilateral_filterBilateralFilterBilateralFilter, anisotropic_diffusionanisotropic_diffusionAnisotropicDiffusionanisotropic_diffusionAnisotropicDiffusionAnisotropicDiffusion, median_imagemedian_imageMedianImagemedian_imageMedianImageMedianImage


Kaiming He, Jian Sun, Xiaoou Tang: “Guided Image Filtering”; IEEE Transactions on Pattern Analysis and Machine Intelligence; PAMI-35, no. 6; S. 1397-1409; 2013.



ClassesClassesClassesClasses | | | | Operators