Main Content


Local entropy of grayscale image



J = entropyfilt(I) returns the array J, where each output pixel contains the entropy value of the 9-by-9 neighborhood around the corresponding pixel in the input image I.

For pixels on the borders of I, entropyfilt uses symmetric padding. In symmetric padding, the values of padding pixels are a mirror reflection of the border pixels in I.

J = entropyfilt(I,nhood) performs entropy filtering of the input image I using the neighborhood nhood.


collapse all

This example shows how to perform entropy filtering using entropyfilt. Brighter pixels in the filtered image correspond to neighborhoods in the original image with higher entropy.

Read an image into the workspace.

I = imread('circuit.tif');

Perform entropy filtering using entropyfilt.

J = entropyfilt(I);

Show the original image and the processed image.

title('Original Image')

Figure contains an axes. The axes with title Original Image contains an object of type image.

title('Result of Entropy Filtering')

Figure contains an axes. The axes with title Result of Entropy Filtering contains an object of type image.

Input Arguments

collapse all

Image to be filtered, specified as a numeric array of any dimension. If the input image has more than two dimensions (ndims(I)>2), such as for an RGB image, then entropyfilt filters all 2-D planes along the higher dimensions.

Data Types: double | uint8 | uint16 | uint32 | logical

Neighborhood, specified as a numeric or logical array containing 0s and 1s. The size of nhood must be odd in each dimension.

By default, entropyfilt uses the neighborhood true(9). The center element of the neighborhood is floor((size(nhood) + 1)/2).

To specify neighborhoods of other shapes, such as a disk, use the strel function to create a structuring element object of the desired shape. Then, extract the neighborhood from the structuring element object’s neighborhood property.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Output Arguments

collapse all

Filtered image, returned as a numeric array the same size as the input image I.

Data Types: double

More About

collapse all


Entropy is a statistical measure of randomness that can be used to characterize the texture of the input image.

Entropy is defined as -sum(p.*log2(p)), where p contains the normalized histogram counts returned from imhist.


  • By default, entropyfilt uses two bins for logical arrays. entropyfilt converts any other class to uint8 for the histogram count calculation and uses 256 bins so that the pixel values are discrete and directly correspond to a bin value.


[1] Gonzalez, R. C., R. E. Woods, and S. L. Eddins. Digital Image Processing Using MATLAB. New Jersey, Prentice Hall, 2003, Chapter 11.

Introduced before R2006a