Created
October 17, 2018 09:30
-
-
Save afzafri/694fb18cdae8ab623173953b6893e7f6 to your computer and use it in GitHub Desktop.
Simple script for calculating histogram equalization for my Image Processing course
This file contains hidden or 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
''' | |
HISTOGRAM EQUALIZATION CALCULATOR | |
Afif Zafri | |
''' | |
from collections import Counter | |
# input | |
gray = [60,7,60,8,60,10,7,30, | |
30,45,15,15,7,15,60,8, | |
10,10,60,8,45,7,7,10, | |
60,30,8,30,60,45,8,30, | |
8,8,10,15,30,8,60,15, | |
45,60,15,30,8,45,8,10, | |
30,7,45,7,60,7,10,45, | |
10,10,30,8,15,10,45,60] | |
total = float(len(gray)) | |
# count occurance of same value, and sort ascending order | |
hist = Counter(gray) | |
hist = sorted(hist.items()) | |
cum = 0.0 | |
print("Histogram values: ") | |
print("Gray \t Hist \t Normalized \t Cummulative \t New Gray") | |
for i in hist: | |
gray = i[0] | |
hist = i[1] | |
norm = float(round(hist/total, 3)) # calc normalized value | |
cum += norm # calc cummulative | |
newgray = int(cum*256) # calc new gray value | |
print(str(gray) + "\t " + str(hist) + "\t\t" + str(norm) + "\t\t" + str(cum) + "\t\t " + str(newgray)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment