在OpenCV和python中快速调整

在OpenCV和python中快速调整

本文介绍了在OpenCV和python中快速调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经有点,但是与 MATLAB的等效功能.在我的计算机上,该函数在python中执行需要1.7秒,而对于MATLAB中的同一图像仅需要0.009秒.结果是一样的,但是速度差距很大.

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.

可以优化吗?还是有其他可以快速进行直方图拉伸的python库?

Can this be optimized? Or are there any other python libraries that can do histogram stretching fast?

推荐答案

这些答案不是很好. imadjust 只是进行线性拉伸.您需要找到上下限(默认情况下,它使用数据的1%和99%).一旦 lower upper ,您就可以

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

您可能需要 img 为浮点类型,才能使其正常工作.

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

有关Numpy中的线性映射,请参见此问题.

See this question for linear mapping in Numpy.

这篇关于在OpenCV和python中快速调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 02:47