-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpencv histogram
More file actions
30 lines (25 loc) · 845 Bytes
/
Opencv histogram
File metadata and controls
30 lines (25 loc) · 845 Bytes
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
import cv2
import matplotlib.pyplot as plt
def main():
path = "D:\\image_processing_files\\Dataset\\"
imgpath = path + "4.2.07.tiff"
img = cv2.imread(imgpath,1)
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
red_hist = cv2.calcHist([img],[0],None,[256],[0,255])
green_hist = cv2.calcHist([img],[1],None,[256],[0,255])
blue_hist = cv2.calcHist([img],[2],None,[256],[0,255])
plt.subplot(3,1,1)
plt.title("Red Histogram")
plt.plot(red_hist,color = 'r')
plt.xlim(xmin = 0,xmax = 256)
plt.subplot(3,1,2)
plt.title("Green Histogram")
plt.plot(green_hist,color = 'g')
plt.xlim(xmin = 0,xmax = 256)
plt.subplot(3,1,3)
plt.title("BLue Histogram")
plt.plot(blue_hist,color = 'b')
plt.xlim(xmin = 0,xmax = 256)
plt.show()
if __name__ == "__main__":
main()