Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- """
- not sure how you're reading images in but this is it
- img = cv2.imread(???,0)
- """
- imgb,imgg,imgr = cv2.split(img)
- histb = np.histogram(imgb.flatten(),256,[0,256])
- binsb = np.histogram(imgb.flatten(),256,[0,256])
- cdfb = hist.cumsum()
- cdfb_normalized = cdfb * histb.max()/ cdfb.max()
- cdfb_m = np.ma.masked_equal(cdfb_m,0)
- cdfb_m = (cdfb_m - cdfb_m.min())*255/(cdfb_m.max()-cdfb_m.min())
- cdfb = np.ma.filled(cdfb_m,0).astype('uint8')
- "
- histg = np.histogram(imgg.flatten(),256,[0,256])
- binsg = np.histogram(imgg.flatten(),256,[0,256])
- cdfg = histg.cumsum()
- cdfg_normalized = cdfg * histg.max()/ cdfg.max()
- cdfg_m = np.ma.masked_equal(cdfg_m,0)
- cdfg_m = (cdfg_m - cdfg_m.min())*255/(cdfg_m.max()-cdfg_m.min())
- cdfg = np.ma.filled(cdfg_m,0).astype('uint8')
- "
- histr = np.histogram(imgr.flatten(),256,[0,256])
- binsr = np.histogram(imgr.flatten(),256,[0,256])
- cdfr = hist.cumsum()
- cdfr_normalized = cdfr * histr.max()/ cdfr.max()
- cdfr_m = np.ma.masked_equal(cdfr,0)
- cdfr_m = (cdf_m - cdf_m.min())*255/(cdfr_m.max()-cdfr_m.min())
- cdfr = np.ma.filled(cdfr_m,0).astype('uint8')
- imgb = cv2.merge((b,g,r))
- img2 = cdf[img]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement