Main Content


Estimate parameters for anisotropic diffusion filtering



[gradientThreshold,numberOfIterations] = imdiffuseest(I) estimates the gradient threshold and number of iterations required to filter the grayscale image I using anisotropic diffusion.

[gradientThreshold,numberOfIterations] = imdiffuseest(I,Name,Value) uses name-value pairs to change the behavior of the anisotropic diffusion algorithm.


collapse all

Read a grayscale image, then apply strong Gaussian noise to it. Display the noisy image.

I = imread('pout.tif');
Inoisy = imnoise(I,'gaussian',0,0.005);
title('Noisy Image')

Estimate the gradient threshold and number of iterations needed to perform anisotropic diffusion filtering of the image.

[gradThresh,numIter] = imdiffuseest(Inoisy)
gradThresh = 1x5 uint8 row vector

   64   50   39   34   29

numIter = 5

Filter the noisy image by using anisotropic diffusion with the estimated parameters.

Idiffuseest = imdiffusefilt(Inoisy,'GradientThreshold', ...

For comparison, also filter the noisy image by using anisotropic diffusion with the default parameters. The default gradient threshold is 25.5 because the data type of the image is uint8, and the default number of iterations is 5.

Idiffusedef = imdiffusefilt(Inoisy);

Visually compare the two filtered images.

 title(['Anisotropic Diffusion Filtering Using ' ...
     'Default Parameters (Left) vs. Estimated Parameters (Right)'])

Some noise remains in the image that was filtered using default parameters. The noise is almost completely absent from the image that was filtered using estimated parameters. The sharpness of edges in both images, especially high-contrast edges such as the trellis and white collar, is preserved.

Input Arguments

collapse all

Image to be filtered, specified as a 2-D grayscale image.

Data Types: single | double | int16 | uint8 | uint16

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: imdiffuseest(I,'Connectivity','minimal') estimates parameters required for anisotropic diffusion on image I, using minimal connectivity.

Connectivity of a pixel to its neighbors, specified as the comma-separated pair consisting of 'Connectivity' and 'maximal' or 'minimal'. Maximal connectivity considers eight nearest neighbors and minimal connectivity considers four nearest neighbors.

Conduction method, specified as the comma-separated pair consisting of 'ConductionMethod' and 'exponential' or 'quadratic'. Exponential diffusion favors high-contrast edges over low-contrast edges. Quadratic diffusion favors wide regions over smaller regions.

Output Arguments

collapse all

Gradient threshold, returned as a numeric vector of the same data type as the input image, I. The length of the vector is equal to numberOfIterations.

Number of iterations to use in the diffusion process, returned as a positive integer.


[1] Perona, P., and J. Malik. "Scale-space and edge detection using anisotropic diffusion." IEEE® Transactions on Pattern Analysis and Machine Intelligence. Vol. 12, No. 7, July 1990, pp. 629–639.

[2] Tsiotsios, C., and M. Petrou. "On the choice of the parameters for anisotropic diffusion in image processing." Pattern Recognition. Vol. 46, No. 5, May 2013, pp. 1369–1381.

Version History

Introduced in R2018a