Last active
January 7, 2017 10:50
-
-
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
This file contains hidden or 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 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey I am having trouble with running this script in djnago. Can you help me out.