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 in python, while it only takes 0.009 seconds for the same image in MATLAB. The result is the same, but the speed gap is enormous.
Can this be optimized? Or are there any other python libraries that can do histogram stretching fast?