Created
February 27, 2019 15:54
-
-
Save JeonghunLee/c79fb515a32d00583e77adf45a9b9677 to your computer and use it in GitHub Desktop.
python Histogram Test program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import random | |
from matplotlib import pyplot as plt | |
from matplotlib.backend_bases import NavigationToolbar2 | |
# https://opencv-python.readthedocs.io/en/latest/doc/19.imageHistograms/imageHistograms.html#mask | |
# https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_histograms/py_histogram_equalization/py_histogram_equalization.html | |
# https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_histograms/py_histogram_begins/py_histogram_begins.html | |
img1 = cv2.imread('/usr/share/scratch/Media/Backgrounds/Outdoors/village.jpg',0) | |
hist1 = cv2.calcHist([img1],[0],None,[256],[0,256]) | |
hist2 = cv2.calcHist([img1],[0],None,[128],[0,128]) | |
hist3 = cv2.calcHist([img1],[0],None,[128],[128,256]) | |
hist4,bins = np.histogram(img1.ravel(),256,[0,256]) | |
print "hist4-128 %d" %(hist4[128]) | |
print "hist1-128 %d" %(hist1[128]) | |
#print "hist2-128 %d" %(hist2[128]) | |
#print "hist2-129 %d" %(hist2[129]) | |
#print "hist2-140 %d" %(hist2[140]) | |
plt.subplot(221),plt.imshow(img1,'gray'),plt.title('Red Line') | |
plt.subplot(222),plt.plot(hist1,color='r'),plt.title | |
plt.subplot(223),plt.plot(hist2,color='g') | |
plt.subplot(224),plt.plot(hist3,color='b') | |
plt.xlim([0,256]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment