Created
November 13, 2016 16:29
-
-
Save leandromoreira/50e12dc47ee56b9912f94054a834bff8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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