Friday, October 16, 2015

Python + OpenCV: generate Histograms of images


Python + OpenCv example run on Raspberry Pi 2 to generate Histograms of images, pyHist.py
from PIL import Image
import numpy as np
from matplotlib import pyplot as plt
import cv2

img = Image.open('photo.jpg')
#img = Image.open('b.png')
imgArr = np.asarray(img)

plt.subplot(221), plt.imshow(img)

color = ('r','g','b')
for i,col in enumerate(color):
    histr = cv2.calcHist([imgArr],[i],None,[256],[0,256])
    plt.subplot(222), plt.plot(histr,color = col)
    plt.xlim([0,256])

plt.xlim([0,256])

plt.show()



Reference: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_histograms/py_histogram_begins/py_histogram_begins.html

2 comments:

Nagisa Furukawa said...

please, how can I install matplotlib in ubuntu (64bits) for python, the commands i used are not working !!

Nagisa Furukawa said...

how can I install matplotlib in ubuntu (64bits) for python, the solutions about sudo and so all didn't work !!