Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from skimage.io import imread, imsave, imshow
- from skimage import img_as_float, img_as_ubyte
- import numpy as np
- img = imread("img.png")
- counts = np.bincount(img.flat, minlength=256)
- mn_cdf = -1
- cdf = [0] * 256
- for i in range(256):
- if i != 0:
- cdf[i] += cdf[i-1]
- cdf[i] += counts[i]
- if mn_cdf == -1 and cdf[i] != 0:
- mn_cdf = cdf[i]
- def f(x):
- return round((cdf[x] - mn_cdf) / (img.shape[0] * img.shape[1] - 1) * 255)
- for i in range(img.shape[0]):
- for j in range(img.shape[1]):
- img[i, j] = f(img[i,j])
- imsave("out_img.png", img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement