given an image I of type uint8
in matlab
entropy(I)
gives me a very different result from
entropy(im2double(I))
(e.g. 6.98 in the first case, 0.51 in the second case) why the datatype changes this value?
When you read an image using imread
, your image is read into a uint
m-by-n-by-3 array. Depending on the image format, 16 or fewer bits per color plane (red, green, blue) are used in order to store image pixels.
uint8
(unsigned 8 bits integer) is a numeric format for integers that allows a minimum value of 0
and a maximum value of 255
. uint16
(unsigned 16 bits integer) is a numeric format for integers that allows a minimum value of 0
and a maximum value of 65535
. When you convert these numerical formats into double
, you are basically dividing them by their maximum value:
% Pseudocode
uint8 val = 127;
double val_new = val / 255.0d; % 0.49803921568627450980392156862745
uint16 val = 42133;
double val_new = val / 65535.0d; % 0.64290836957351033798733501182574
The double
numerical format is normally used to store very big (64 bits) floating-point values that need to ensure a high precision. This means that your uint
values will be converted into 0.something
values, where something
represents a (variable but potentially) huge amount of digits.
Since the Shannon Entropy (more info here) is defined as the average amount of information produced by a stochastic source of data... your result is easily explained: you are feeding the entropy
function with a higher degree of information (greater amount of bytes, greater amount of digits, greater amount of information).