Last active
March 1, 2018 06:14
-
-
Save satriahrh/b0269c07cca64d69915932231c11f421 to your computer and use it in GitHub Desktop.
Histogram code on github.com/hafizhme/phocode that seems can't affordable on it
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
from PIL import Image | |
import matplotlib | |
import matplotlib.pyplot as plt | |
matplotlib.use('agg') | |
def do(original_image: Image): | |
freq = [ | |
[0 for x in range(256)], | |
[0 for x in range(256)], | |
[0 for x in range(256)], | |
] | |
for x in range(original_image.size[0]): | |
for y in range(original_image.size[1]): | |
px = original_image.getpixel((x, y)) | |
freq[0][px[0]] += 1 | |
freq[1][px[1]] += 1 | |
freq[2][px[2]] += 1 | |
figure, axarr = plt.subplots(3) | |
colors = ('red', 'green', 'blue') | |
data = (freq[0], freq[1], freq[2]) | |
subplots = range(3) | |
bands_range = range(256) | |
for data, i, color in zip(data, subplots, colors): | |
axarr[i].bar( | |
bands_range, | |
data, | |
width=2, | |
facecolor=color | |
) | |
axarr[i].set_xlim( | |
(0, 255) | |
) | |
figure.subplots_adjust(hspace=0.3) | |
return plt, None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment