Pomah3

Untitled

Apr 13th, 2021
658
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from skimage.io import imread, imsave, imshow
  2. from skimage import img_as_float, img_as_ubyte
  3. import numpy as np
  4.  
  5. img = imread("img.png")
  6.  
  7. counts = np.bincount(img.flat, minlength=256)
  8.  
  9. mn_cdf = -1
  10. cdf = [0] * 256
  11. for i in range(256):
  12.     if i != 0:
  13.         cdf[i] += cdf[i-1]
  14.        
  15.     cdf[i] += counts[i]
  16.     if mn_cdf == -1 and cdf[i] != 0:
  17.         mn_cdf = cdf[i]
  18.        
  19. def f(x):
  20.     return round((cdf[x] - mn_cdf) / (img.shape[0] * img.shape[1] - 1) * 255)
  21.  
  22. for i in range(img.shape[0]):
  23.     for j in range(img.shape[1]):
  24.         img[i, j] = f(img[i,j])
  25.  
  26. imsave("out_img.png", img)
  27.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×