MCPcopy Create free account
hub / github.com/modelscope/modelscope / equalize_func

Function equalize_func

modelscope/preprocessors/ofa/utils/vision_helper.py:47–68  ·  view source on GitHub ↗

same output as PIL.ImageOps.equalize PIL's implementation is different from cv2.equalize

(img)

Source from the content-addressed store, hash-verified

45
46
47def 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
71def rotate_func(img, degree, fill=(0, 0, 0)):

Callers

nothing calls this directly

Calls 2

tune_channelFunction · 0.85
mergeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…