Popular Posts

Jun 25, 2020

Histogram - Python(OpenCV)



import numpy as np
import cv2 as cv
from matplotlib import pyplot as pit

img = cv.imread(
"lena.jpg")
#img = np.zeros((200, 200), np.uint8)
#cv.rectangle(img, (0, 100), (200, 200), (255), -1)
#cv.rectangle(img, (0, 50), (100, 100), (127), -1)

b, g, r = cv.split(img)

cv.imshow(
"img", img)
cv.imshow(
"b", b)
cv.imshow(
"g", g)
cv.imshow(
"r", r)


pit.hist(b.ravel()
, 256, [0, 250])
pit.hist(g.ravel()
, 256, [0, 256])
pit.hist(r.ravel()
, 256, [0, 256])
pit.show()

cv.waitKey(
0)
cv.destroyAllWindows()

No comments:

Post a Comment