Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. """
  5. not sure how you're reading images in but this is it
  6.  
  7. img = cv2.imread(???,0)
  8.  
  9. """
  10. imgb,imgg,imgr = cv2.split(img)
  11.  
  12.  
  13. histb = np.histogram(imgb.flatten(),256,[0,256])
  14. binsb = np.histogram(imgb.flatten(),256,[0,256])
  15.  
  16. cdfb = hist.cumsum()
  17. cdfb_normalized = cdfb * histb.max()/ cdfb.max()
  18.  
  19. cdfb_m = np.ma.masked_equal(cdfb_m,0)
  20. cdfb_m = (cdfb_m - cdfb_m.min())*255/(cdfb_m.max()-cdfb_m.min())
  21. cdfb = np.ma.filled(cdfb_m,0).astype('uint8')
  22.  
  23. "
  24.  
  25. histg = np.histogram(imgg.flatten(),256,[0,256])
  26. binsg = np.histogram(imgg.flatten(),256,[0,256])
  27.  
  28. cdfg = histg.cumsum()
  29. cdfg_normalized = cdfg * histg.max()/ cdfg.max()
  30.  
  31. cdfg_m = np.ma.masked_equal(cdfg_m,0)
  32. cdfg_m = (cdfg_m - cdfg_m.min())*255/(cdfg_m.max()-cdfg_m.min())
  33. cdfg = np.ma.filled(cdfg_m,0).astype('uint8')
  34.  
  35. "
  36.  
  37. histr = np.histogram(imgr.flatten(),256,[0,256])
  38. binsr = np.histogram(imgr.flatten(),256,[0,256])
  39.  
  40. cdfr = hist.cumsum()
  41. cdfr_normalized = cdfr * histr.max()/ cdfr.max()
  42.  
  43. cdfr_m = np.ma.masked_equal(cdfr,0)
  44. cdfr_m = (cdf_m - cdf_m.min())*255/(cdfr_m.max()-cdfr_m.min())
  45. cdfr = np.ma.filled(cdfr_m,0).astype('uint8')
  46.  
  47. imgb = cv2.merge((b,g,r))
  48.  
  49. img2 = cdf[img]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement