Unverified Commit 366c628a authored by Ma Zerun's avatar Ma Zerun Committed by GitHub
Browse files

[Fix] Fix potential interger overflow in `imequalize`. (#1198)

* Fix potential interger overflow in `imequalize`.

* Modify imequalize unit test image size to generate potential integer
overflow.
parent 6659c38d
......@@ -157,6 +157,8 @@ def imequalize(img):
lut = (np.cumsum(histo) + (step // 2)) // step
# Shift lut, prepending with 0.
lut = np.concatenate([[0], lut[:-1]], 0)
# handle potential integer overflow
lut[lut > 255] = 255
# If step is zero, return the original image.
# Otherwise, index from lut.
return np.where(np.equal(step, 0), im, lut[im])
......
......@@ -131,8 +131,7 @@ class TestPhotometric:
# test equalize with randomly sampled image.
for _ in range(nb_rand_test):
img = np.clip(
np.random.normal(0, 1, (1000, 1200, 3)) * 260, 0,
img = np.clip(np.random.normal(0, 1, (256, 256, 3)) * 260, 0,
255).astype(np.uint8)
equalized_img = mmcv.imequalize(img)
assert_array_equal(equalized_img, _imequalize(img))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment