Skip to content Skip to sidebar Skip to footer

Fast Imadjust In Opencv And Python

This has been somewhat answered before, however the solution is extremely slow compared to MATLAB's equivalent function. On my computer, the function takes 1.7 seconds to execute i

Solution 1:

Those answers are not very good. imadjust simply does a linear stretch. You need to find the lower and upper bound (by default it uses the 1% and 99% of the data). Once you have lower and upper, you can just

out = (img - lower) * (255 / (upper - lower)
np.clip(out, 0, 255, out) # in-place clipping

You probably need img to be of a floating-point type for that to work correctly.

See this question for linear mapping in Numpy.

Post a Comment for "Fast Imadjust In Opencv And Python"