same output as PIL.ImageOps.equalize PIL's implementation is different from cv2.equalize
(img)
| 45 | |
| 46 | |
| 47 | def equalize_func(img): |
| 48 | ''' |
| 49 | same output as PIL.ImageOps.equalize |
| 50 | PIL's implementation is different from cv2.equalize |
| 51 | ''' |
| 52 | n_bins = 256 |
| 53 | |
| 54 | def tune_channel(ch): |
| 55 | hist = cv2.calcHist([ch], [0], None, [n_bins], [0, n_bins]) |
| 56 | non_zero_hist = hist[hist != 0].reshape(-1) |
| 57 | step = np.sum(non_zero_hist[:-1]) // (n_bins - 1) |
| 58 | if step == 0: |
| 59 | return ch |
| 60 | n = np.empty_like(hist) |
| 61 | n[0] = step // 2 |
| 62 | n[1:] = hist[:-1] |
| 63 | table = (np.cumsum(n) // step).clip(0, 255).astype(np.uint8) |
| 64 | return table[ch] |
| 65 | |
| 66 | channels = [tune_channel(ch) for ch in cv2.split(img)] |
| 67 | out = cv2.merge(channels) |
| 68 | return out |
| 69 | |
| 70 | |
| 71 | def rotate_func(img, degree, fill=(0, 0, 0)): |
nothing calls this directly
no test coverage detected
searching dependent graphs…