Why does the Image Processing Toolbox (R2007a) ENTROPY command return a value of zero when the image is cast as a double?

Currently, the documentation for the ENTROPY function states that it should work with images of data type double. However, if an image 'I' is explicitly cast as a double by:
I=double(I);
ENTROPY returns a value of zero due to scaling issues. The code I used is as follows:
I = rgb2gray(ColorImage); % use any image
ent1 = entropy(I);
I = double(I);
ent2 = entropy(I);

 Accepted Answer

Some of the Image Processing Toolbox functions have to assume a particular dynamic range. By convention, this range is [0,1] for data of type 'double', but [0,255] for data of type 'uint8'. Therefore, the IM2DOUBLE function should be used as it handles this scaling automatically. For example, your code thus becomes:
I = rgb2gray(ColorImage); % use any true color image
ent1 = entropy(I);
I = im2double(I);
ent2 = entropy(I);
Both 'ent1' and 'ent2' should be equal.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!