-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimpleHistogram_GrayScaleImage.py
More file actions
40 lines (30 loc) · 1.08 KB
/
Copy pathSimpleHistogram_GrayScaleImage.py
File metadata and controls
40 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# This program is written by Abubakr Shafique (abubakr.shafique@gmail.com)
import numpy as np #This is to deal with numbers and arrays
import cv2 as cv #This is to deal with images
from matplotlib import pyplot as plt
def Histogram_Computation(Image):
Image_Height = Image.shape[0]
Image_Width = Image.shape[1]
Histogram = np.zeros([256], np.int32)
for x in range(0, Image_Height):
for y in range(0, Image_Width):
Histogram[Image[x,y]] +=1
return Histogram
def Plot_Histogram(Histogram):
plt.figure()
plt.title("GrayScale Histogram")
plt.xlabel("Intensity Level")
plt.ylabel("Intensity Frequency")
plt.xlim([0, 256])
plt.plot(Histogram)
plt.savefig("Histogram_GrayScale.jpg")
def main():
Input_Image = cv.imread("Test_Image.png",0) # This is to read Gray Scale Image
Histogram_GrayScale = Histogram_Computation(Input_Image)
#Now to print our output Histogram
for i in range(0,len(Histogram_GrayScale)):
print("Histogram[",i,"]: ", Histogram_GrayScale[i])
Plot_Histogram(Histogram_GrayScale)
input("Please Enter to Continue...")
if __name__ == '__main__':
main()