Guided filtering of images
B = imguidedfilter(A,G)
B = imguidedfilter(A)
B = imguidedfilter(__,Name,Value,...)
This example shows how to perform edge-preserving smoothing using a guide filter.
Read an image into the workspace.
A = imread('pout.tif');
Smooth the image using
imguidefilter. In this syntax,
imguidedfilter uses the image itself as the guidance image.
Ismooth = imguidedfilter(A);
Display the original image and the smoothed image side-by-side.
A— Image to be filtered
Image to be filtered, specified as a nonsparse, binary, grayscale, or RGB image.
G— Image to use as a guide during filtering
Image to use as a guide during filtering, specified as a nonsparse, binary, grayscale, or RGB image.
Specify optional comma-separated pairs of
Name is the argument
Value is the corresponding
Name must appear
inside single quotes (
You can specify several name and value pair
arguments in any order as
Ismooth = imguidedfilter(A,'NeighborhoodSize',[4 4]);
'NeighborhoodSize'— Size of the rectangular neighborhood around each pixel used in guided filtering
[5 5](default) | scalar or two-element vector of positive integers
Size of the rectangular neighborhood around each pixel used
in guided filtering, specified as a scalar or a two-element vector,
N], of positive integers. If you specify a scalar value,
Q, the neighborhood is a square of size
Ismooth = imguidedfilter(A,'NeighborhoodSize',[4
'DegreeOfSmoothing'— Amount of smoothing in the output image
0.01*diff(getrangefromclass(G)).^2(default) | positive scalar
Amount of smoothing in the output image, specified as a positive scalar. If you specify a small value, only neighborhoods with small variance (uniform areas) will get smoothed and neighborhoods with larger variance (such as around edges) will not be smoothed. If you specify a larger value, high variance neighborhoods, such as stronger edges, will get smoothed in addition to the relatively uniform neighborhoods. Start with the default value, check the results, and adjust the default up or down to achieve the effect you desire.
a soft threshold on variance for the given neighborhood. If a pixel's
neighborhood has variance much lower than the threshold, it will see
some amount of smoothing. If a pixel's neighborhood has variance
much higher than the threshold it will have little to no smoothing.
have different number of channels.
A is an
G is a grayscale or binary image,
guidance for all the channels of
imguidedfilter uses each channel of
guidance for the corresponding channel of
A is a grayscale or binary
G is an RGB image,
all the three channels of
G for guidance (color
statistics) for filtering
 Kaiming He, Jian Sun, Xiaou Tang, Guided Image Filtering. IEEE Transactions on Pattern Analysis and Machine Intelligence, Volume 35, Issue 6, pp. 1397-1409, June 2013