-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimpleHistogram_ColorImage.py
More file actions
46 lines (35 loc) · 1.38 KB
/
Copy pathSimpleHistogram_ColorImage.py
File metadata and controls
46 lines (35 loc) · 1.38 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
41
42
43
44
45
46
# This Program is written by Abubakr Shafique (abubakr.shafique@gmail.com)
import numpy as np #This is to deal with nimbers 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]
Image_Channels = Image.shape[2]
Histogram = np.zeros([256, Image_Channels], np.int32)
for x in range(0, Image_Height):
for y in range(0, Image_Width):
for c in range(0, Image_Channels):
Histogram[Image[x,y,c], c] +=1
return Histogram
def Plot_Histogram(Histogram):
plt.figure()
plt.title("Color Image Histogram")
plt.xlabel("Intensity Level")
plt.ylabel("Intensity Frequency")
plt.xlim([0, 256])
plt.plot(Histogram[:,0],'b') # This is to Plot Blue Channel with Blue Color
plt.plot(Histogram[:,1],'g') # This is to Plot Green Channel with Green Color
plt.plot(Histogram[:,2],'r') # This is to Plot Red Channel with Red Color
plt.savefig("Color_Histogram.jpg")
def main():
Input_Image = cv.imread("Test_Image.png") #This will read a color Images
Histogram = Histogram_Computation(Input_Image)
#Now to print our result
for i in range(0, Histogram.shape[0]):
for c in range(0, Histogram.shape[1]):
print("Histogram[", i, ", ", c, "]: ", Histogram[i,c])
Plot_Histogram(Histogram)
input("Please Enter to Continue...")
if __name__ == '__main__':
main()