defget_dark(src, exps,r=1): t = np.min(src, axis=2) w, h = t.shape v = t.copy() for i in range(r+1): v[0:w-i, 0:h - i] = np.min(np.stack([v[0:w-i, 0:h-i], t[i:w, i:h]], axis=2), axis=2) v[i:w, i:h] = np.min( np.stack([v[i:w, i:h], t[0:w-i, 0:h-i]], axis=2), axis=2) res = guidefilter(t, v, r, exps) cv2.imshow("dark",np.hstack([v,res]).astype(np.uint8)) return res
defget_v(src, exps,r=1): t = np.min(src, axis=2) w, h = t.shape v = t.copy() for i in range(r+1): v[0:w-i, 0:h - i] = np.min(np.stack([v[0:w-i, 0:h-i], t[i:w, i:h]], axis=2), axis=2) v[i:w, i:h] = np.min( np.stack([v[i:w, i:h], t[0:w-i, 0:h-i]], axis=2), axis=2) res = guidefilter(t, v, r, exps) # cv2.imshow("dark",np.hstack([v,res]).astype(np.uint8)) return res
defget_A(src,dark): bins = 2000 ht = np.histogram(dark, bins) d = np.cumsum(ht[0])/float(dark.size) for lmax in range(bins-1, 0, -1): if d[lmax]<=0.999: break A = np.mean(src,2)[dark>=ht[1][lmax]].max() return A