Skip to content

Instantly share code, notes, and snippets.

@khrlimam
Last active January 7, 2017 10:50
Show Gist options
  • Save khrlimam/cb1339777f6807ac7e9d403cbcb80778 to your computer and use it in GitHub Desktop.
Save khrlimam/cb1339777f6807ac7e9d403cbcb80778 to your computer and use it in GitHub Desktop.
Here is the snippet i use in https://web.facebook.com/notes/khairul-imam/rgb-color-channel-quick-glance/519312241608587. No need to create a new file, you can use IPython just to test the code. Make sure you have numpy, scipy, matplotlib installed in your virtualenvironment or computer
import cv2 as cv
from matplotlib import pyplot as plt
#load image
rgb_image = cv.imread('images/bebek_imut.jpg')
#see the output
rgb_image
#print rgb_image's shape
rgb_image.shape
#split rgb_image into individual color in b,g,r order
split_rgb = cv.split(rgb_image)
#print splitted color
split_rgb
#create a histogram for each color channel
colors = ('b','g','r')
plt.figure()
plt.title('RGB Channel Histogram ')
plt.xlabel('Grayscale value')
plt.ylabel('frequency')
#loop over channels
for color, channel in zip(colors, split_rgb):
histogram = cv.calcHist([channel], [0], None, [256], [0, 256])
plt.plot(histogram, color=color)
plt.xlim([0, 256])
#show the histogram
plt.show()
@vishnuiyer
Copy link

Hey I am having trouble with running this script in djnago. Can you help me out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment