【Python OPENCV】 histograms

 import cv2

import numpy as np

# We need to import matplotlib to create our histogram plots
from matplotlib import pyplot as plt

image = cv2.imread('images/input.jpg')

histogram = cv2.calcHist([image], [0], None, [256], [0256])

# We plot a histogram, ravel() flatens our image array 
plt.hist(image.ravel(), 256, [0256]); plt.show()

# Viewing Separate Color Channels
color = ('b''g''r')

# We now separate the colors and plot each in the Histogram
for i, col in enumerate(color):
    histogram2 = cv2.calcHist([image], [i], None, [256], [0256])
    plt.plot(histogram2, color = col)
    plt.xlim([0,256])
    
plt.show()

No comments:

This will make you a better decision maker | Annie Duke (author of “Thinking in Bets” and “Quit”, former pro poker…

Annie is a former professional poker player, decision-making expert, author, and special partner at First Round Capital.  ͏     ­͏     ­͏   ...

Contact Form

Name

Email *

Message *