Skip to content

Instantly share code, notes, and snippets.

@leandromoreira
Created November 13, 2016 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leandromoreira/50e12dc47ee56b9912f94054a834bff8 to your computer and use it in GitHub Desktop.
Save leandromoreira/50e12dc47ee56b9912f94054a834bff8 to your computer and use it in GitHub Desktop.
Image = imread('Cameraman256.bmp');
Frequency = zeros(256);
Samples = 256 * 256;
for i = 1:256
for j = 1:256
% convert 0-255 to index-wise
IntensityIndex = Image(i,j) + 1;
Frequency(IntensityIndex) = Frequency(IntensityIndex) + 1;
end
end
FinalEntropy=0;
for i = 1:256
Probability = Frequency(i) / Samples;
if Probability ~= 0
Entropy = -1 * Probability * log2(Probability);
FinalEntropy = FinalEntropy + Entropy;
end
end
FinalEntropy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment