Created
August 24, 2013 19:34
-
-
Save lizecillie/6330006 to your computer and use it in GitHub Desktop.
histogram_equalization.py
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
def histogram_equalization_point_transformation(A): | |
B = A.copy() | |
P1 = B[:, :, 0] | |
P2 = B[:, :, 1] | |
P3 = B[:, :, 2] | |
G = (np.sum(B * (1/3, 1/3, 1/3), axis=2))/255 | |
rows = G.shape[0] | |
columns = G.shape[1] | |
histogram, bin_edges = np.histogram(G.flatten(), range=(0, 1), bins=256) | |
histogram = histogram/histogram.max() | |
c = histogram.cumsum() | |
c = c/c.max() | |
P1 = 255*P1 | |
P2 = 255*P2 | |
P3 = 255*P3 | |
for i in xrange(rows): | |
for j in xrange(columns): | |
P1[i, j] = c[P1[i, j]] | |
P2[i, j] = c[P2[i, j]] | |
P3[i, j] = c[P3[i, j]] | |
return B | |
A = img_as_float(io.imread('spaghetti.jpg', plugin='pil')) | |
out1 = histogram_equalization_point_transformation(A) | |
f1, (ax0, ax1) = plt.subplots(1, 2) | |
f1.tight_layout() | |
ax0.imshow(A) | |
ax0.set_title('Input image') | |
ax1.imshow(out1) | |
ax1.set_title('Histogram equalization point transformation applied to R, G and B panels') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment