same output as PIL.ImageOps.equalize PIL's implementation is different from cv2.equalize
(img)
| 116 | |
| 117 | |
| 118 | def equalize_func(img): |
| 119 | ''' |
| 120 | same output as PIL.ImageOps.equalize |
| 121 | PIL's implementation is different from cv2.equalize |
| 122 | ''' |
| 123 | n_bins = 256 |
| 124 | |
| 125 | def tune_channel(ch): |
| 126 | hist = cv2.calcHist([ch], [0], None, [n_bins], [0, n_bins]) |
| 127 | non_zero_hist = hist[hist != 0].reshape(-1) |
| 128 | step = np.sum(non_zero_hist[:-1]) // (n_bins - 1) |
| 129 | if step == 0: |
| 130 | return ch |
| 131 | n = np.empty_like(hist) |
| 132 | n[0] = step // 2 |
| 133 | n[1:] = hist[:-1] |
| 134 | table = (np.cumsum(n) // step).clip(0, 255).astype(np.uint8) |
| 135 | return table[ch] |
| 136 | |
| 137 | channels = [tune_channel(ch) for ch in cv2.split(img)] |
| 138 | out = cv2.merge(channels) |
| 139 | return out |
| 140 | |
| 141 | |
| 142 | def rotate_func(img, degree, fill=(0, 0, 0)): |
nothing calls this directly
no test coverage detected