MCPcopy Create free account
hub / github.com/OpenBMB/MiniCPM-V / equalize_func

Function equalize_func

omnilmm/model/utils.py:118–139  ·  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

116
117
118def 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
142def rotate_func(img, degree, fill=(0, 0, 0)):

Callers

nothing calls this directly

Calls 1

tune_channelFunction · 0.85

Tested by

no test coverage detected