Professional Documents
Culture Documents
Lab 1
Lab 1
To use this as a remapping function, we have to normalize such that the maximum
value is 255 ( or the maximum value for the intensity of the image ).
Use a simple remapping procedure to obtain the intensity values of the equalized image:
try:
import seaborn as sns
import pandas as pd
except:
raise Exception('Seaborn or Pandas packages not found. Installation: $ pip install seaborn
pandas')
def create_histogram(img):
assert len(img.shape) == 2 # check grayscale image
histogram = [0] * 256 # list of intensity frequencies, 256 zero values
for row in range(img.shape[0]): # traverse by row (y-axis)
for col in range(img.shape[1]): # traverse by column (x-axis)
histogram[img[row, col]] += 1
return histogram
fig = sns_hist.get_figure()
fig.savefig(output)
return output
# normalize H'
#max_H = max(new_H)
#max_hist = max(histogram)
#new_H = [(f/max_H)*max_hist for f in new_H]
print("H':", new_H)
if __name__ == "__main__":
assert len(sys.argv) == 2, '[USAGE] $ python %s imgage.jpg' %
(os.path.basename(__file__), INPUT)
INPUT = sys.argv[1]
assert os.path.isfile(INPUT), '%s not found' % INPUT
new_histogram = create_histogram(equalized_img)
print('new_histogram:', new_histogram)
hist_img_path = visualize_histogram(new_histogram, output='histogram_eq.png')
print('Saved new histogram @ %s' % hist_img_path)