I found what looks like a Linux-specific recipe here.
For windows I think you need to find out what function you need to call in which dll (probably driver-specific) and use ctypes to make the required call.
def brightness_contrast(image, brightness = -100, contrast = 300):
def vect(a):
c = contrast
b = 100 * brightness
res = ((a - 127.5) * c + 127.5) + b
if res < 0 :
return 0
if res > 255:
return 255
return res
transform = np.vectorize(vect)
data = transform(fromimage(image)).astype(np.uint8)
return toimage(data)
def brightness_contrast(image, brightness = -100, contrast = 300):
def vect(a):
c = contrast
b = 100 * brightness
res = ((a - 127.5) * c + 127.5) + b
if res < 0 :
return 0
if res > 255:
return 255
return res
transform = np.vectorize(vect)
data = transform(fromimage(image)).astype(np.uint8)
return toimage(data)
发布评论
评论(3)
这是特定于操作系统的事情,如果没有特定于系统的绑定可能无法实现。
This is something that is OS-specific and probably not doable without system-specific bindings.
我在此处找到了看起来像 Linux 特定配方的内容。
对于 Windows,我认为您需要找出需要在哪个 dll 中调用什么函数(可能是特定于驱动程序)并使用 ctypes 进行所需的调用。
I found what looks like a Linux-specific recipe here.
For windows I think you need to find out what function you need to call in which dll (probably driver-specific) and use ctypes to make the required call.
我使用此处定义的方程。
因此,要同时调整对比度和亮度,请对每个像素执行以下操作:
下面是一个很好的函数来完成这项工作:
您可以像这样使用它:
我认为这个函数应该更好,关于参数。实际上,没有限制,我应该更新代码以以百分比形式进行参数。
I m using the equation define here.
So, to adjust contrast and brightness at the same time, do for each pixel:
Bellow a nice function which do the job :
You can use it like this:
I think this function should be better, regarding paramaters. Actually, there is no limit, I should update the code to make arguments in percent.