Skip to content

guided_filterGuidedFilterGuidedFilterguided_filterguided_filterπŸ”—

Short descriptionπŸ”—

guided_filterGuidedFilterGuidedFilterguided_filterguided_filter β€” Guided filtering of an image.

SignatureπŸ”—

guided_filter( image Image, image ImageGuide, out image ImageGuided, integer Radius, real Amplitude )void GuidedFilter( const HObject& Image, const HObject& ImageGuide, HObject* ImageGuided, const HTuple& Radius, const HTuple& Amplitude )static void HOperatorSet.GuidedFilter( HObject image, HObject imageGuide, out HObject imageGuided, HTuple radius, HTuple amplitude )def guided_filter( image: HObject, image_guide: HObject, radius: int, amplitude: float ) -> HObject

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 )

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

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

DescriptionπŸ”—

guided_filterGuidedFilter filters the input Imageimageimage using the guidance image ImageGuideimageGuideimage_guide and returns the result in ImageGuidedimageGuidedimage_guided. Imageimageimage and ImageGuideimageGuideimage_guide must be of the same size and type.

The Radiusradiusradius 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 Radiusradiusradius does not influence the runtime of the operator.

Amplitudeamplitudeamplitude is used to decide what is an edge and what is a homogeneous area. Bigger values of Amplitudeamplitudeamplitude lead to stronger edges being smoothed. As a rule of thumb, Amplitudeamplitudeamplitude 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 Amplitudeamplitudeamplitude and adjust the parameter accordingly.

Influence of the Guidance ImageπŸ”—

If Imageimageimage and ImageGuideimageGuideimage_guide are identical, guided_filterGuidedFilter behaves like an edge-preserving smoothing with a filter mask with Radiusradiusradius. Pixels at edges that have a contrast significantly greater than Amplitudeamplitudeamplitude are preserved, while pixels in homogeneous areas are smoothed. Hence, guided_filterGuidedFilter is a fast alternative to anisotropic_diffusionAnisotropicDiffusion or bilateral_filterBilateralFilter.

Β 
(1) (2) (3)

(1) Imageimageimage and (2) ImageGuideimageGuideimage_guide are identical. That leads to edge-preserving smoothing in (3) ImageGuidedimageGuidedimage_guided.

If Imageimageimage and ImageGuideimageGuideimage_guide are different, Imageimageimage is smoothed with a filter mask with Radiusradiusradius, except in areas where ImageGuideimageGuideimage_guide has edges with a contrast significantly greater than Amplitudeamplitudeamplitude.

Β 
(1) (2) (3)

(1) Imageimageimage and (2) ImageGuideimageGuideimage_guide are different. (3) ImageGuidedimageGuidedimage_guided: Only edges are preserved where ImageGuideimageGuideimage_guide has edges.

If ImageGuideimageGuideimage_guide is constant, guided_filterGuidedFilter is equivalent to 2 consecutive calls of mean_imageMeanImage with mask size 2*Radiusradiusradius+1.

Β 
(1) (2) (3)

(2) ImageGuideimageGuideimage_guide is constant. This is equivalent to a double smoothing of (1) Imageimageimage with mean_imageMeanImage. (3) ImageGuidedimageGuidedimage_guided

Influence of the smoothing parametersπŸ”—

The following examples show the influence of Amplitudeamplitudeamplitude 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 Imageimageimage and ImageGuideimageGuideimage_guide.

Filter result with Amplitudeamplitudeamplitude = 1: No effect because Amplitudeamplitudeamplitude is below noise level. Therefore noise is treated as edge and preserved.

Filter result with Amplitudeamplitudeamplitude = 25: Noise is smoothed, edges are preserved.

Filter result with Amplitudeamplitudeamplitude = 50: The weaker edge is smoothed, the stronger edge is preserved.

Filter result with Amplitudeamplitudeamplitude = 100: Both edges are smoothed.

Rolling Guided FilterπŸ”—

guided_filterGuidedFilter 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)GenImageProto(Image, ImageStructure, 0)GenImageProto(Image, ImageStructure, 0)gen_image_proto(Image, ImageStructure, 0)gen_image_proto(Image, ImageStructure, 0)
for I := 1 to 4 by 1
\(\qquad\)guided_filter(Image, ImageStructure, ImageStructure, 1.5, 10)GuidedFilter(Image, ImageStructure, ImageStructure, 1.5, 10)GuidedFilter(Image, ImageStructure, ImageStructure, 1.5, 10)guided_filter(Image, ImageStructure, ImageStructure, 1.5, 10)guided_filter(Image, ImageStructure, ImageStructure, 1.5, 10)
endfor
* Separate texture by subtracting large structures from the original.
sub_image(Image, ImageStructure, ImageTexture, 1, 128)SubImage(Image, ImageStructure, ImageTexture, 1, 128)SubImage(Image, ImageStructure, ImageTexture, 1, 128)sub_image(Image, ImageStructure, ImageTexture, 1, 128)sub_image(Image, ImageStructure, ImageTexture, 1, 128)

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

Mathematical BackgroundπŸ”—

The calculation of the filtered gray value \(I'_{i}\) at the position \(i\) is done according to the following formula:

\[\begin{eqnarray*} I'_{i}=\overline{a_{i}} G_{i} + \overline{b_{i}} \end{eqnarray*}\]

where

\[\begin{eqnarray*} a_{i} = \frac{\frac{1}{\vert \omega_{i} \vert} \sum_{k \in \omega_{i}} G_{k} I_{k} - \overline{G_{i}} \overline{I_{i}}} {\sigma_{G_{i}}^2 + Amplitude^2} \end{eqnarray*}\]

and

\[\begin{eqnarray*} b_{i}=\overline{I_{i}}-a_{i} \overline{G_{i}} \end{eqnarray*}\]

where \(I_{i}\) and \(G_{i}\) are the gray values of Imageimageimage and ImageGuideimageGuideimage_guide at the pixel position \(i\), \(\omega_{i}\) is the neighborhood with radius Radiusradiusradius around the pixel \(i\), \(\overline{a_{i}}\), \(\overline{b_{i}}\), \(\overline{I_{i}}\), and \(\overline{G_{i}}\) are the mean of all \(a\), \(b\), \(I\), or \(G\) in \(\omega_{i}\), \(\sigma_{G_{i}}\) is the standard deviation of all gray values of \(G\) in \(\omega_{i}\), and \(|\omega_{i}|\) is the number of pixels in \(\omega_{i}\).

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

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

  • Automatically parallelized on channel level.

  • Automatically parallelized on domain level.

ParametersπŸ”—

Imageimageimage (input_object) (multichannel-)image(-array) β†’ object (byte / uint2 / real)HObject (byte / uint2 / real)HImage (byte / uint2 / real)HObject (byte / uint2 / real)Hobject (byte / uint2 / real)

Input image.

ImageGuideimageGuideimage_guide (input_object) (multichannel-)image(-array) β†’ object (byte / uint2 / real)HObject (byte / uint2 / real)HImage (byte / uint2 / real)HObject (byte / uint2 / real)Hobject (byte / uint2 / real)

Guidance image.

ImageGuidedimageGuidedimage_guided (output_object) (multichannel-)image(-array) β†’ object (byte / uint2 / real)HObject (byte / uint2 / real)HImage (byte / uint2 / real)HObject (byte / uint2 / real)Hobject * (byte / uint2 / real)

Output image.

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

Radius of the filtering operation.

Default: 33
Suggested values: 1, 2, 3, 5, 101, 2, 3, 5, 10
Restriction: Radius > 0

Amplitudeamplitudeamplitude (input_control) real β†’ (real)HTuple (double)HTuple (double)floatHtuple (double)

Controls the influence of edges on the smoothing.

Default: 20.020.0
Suggested values: 3.0, 10.0, 20.0, 50.0, 100.03.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)
endfor

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

read_imageReadImage

Possible successors

thresholdThreshold, dyn_thresholdDynThreshold, regiongrowingRegiongrowing

Alternatives

bilateral_filterBilateralFilter, anisotropic_diffusionAnisotropicDiffusion, median_imageMedianImage

ReferencesπŸ”—

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.

ModuleπŸ”—

Foundation