Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python PIL:改变色调和饱和度_Python_Image Processing_Python Imaging Library_Pillow_Hue - Fatal编程技术网

python PIL:改变色调和饱和度

python PIL:改变色调和饱和度,python,image-processing,python-imaging-library,pillow,hue,Python,Image Processing,Python Imaging Library,Pillow,Hue,从GIMP,我可以很容易地改变色调和饱和度。例如,下面是将色调设置为-90,饱和度设置为100后的原始图片和最终结果 如何从Python PIL获得相同的结果 原画 最后一张照片 您可以将colorsys模块和PIL组合使用,但速度有点慢colorsys允许您将颜色空间更改为HSV,在HSV中进行色调和饱和度修改非常简单。我将饱和度取为0.65的幂来近似您的示例,它保留了colorsys所需的0.0-1.0范围,同时增加了中间值 import colorsys from PIL import

从GIMP,我可以很容易地改变色调和饱和度。例如,下面是将色调设置为-90,饱和度设置为100后的原始图片和最终结果

如何从Python PIL获得相同的结果

原画

最后一张照片

您可以将
colorsys
模块和
PIL
组合使用,但速度有点慢
colorsys
允许您将颜色空间更改为HSV,在HSV中进行色调和饱和度修改非常简单。我将饱和度取为0.65的幂来近似您的示例,它保留了
colorsys
所需的0.0-1.0范围,同时增加了中间值

import colorsys
from PIL import Image
im = Image.open(filename)
ld = im.load()
width, height = im.size
for y in range(height):
    for x in range(width):
        r,g,b = ld[x,y]
        h,s,v = colorsys.rgb_to_hsv(r/255., g/255., b/255.)
        h = (h + -90.0/360.0) % 1.0
        s = s**0.65
        r,g,b = colorsys.hsv_to_rgb(h, s, v)
        ld[x,y] = (int(r * 255.9999), int(g * 255.9999), int(b * 255.9999))

您可以将
colorsys
模块和
PIL
组合使用,但速度有点慢
colorsys
允许您将颜色空间更改为HSV,在HSV中进行色调和饱和度修改非常简单。我将饱和度取为0.65的幂来近似您的示例,它保留了
colorsys
所需的0.0-1.0范围,同时增加了中间值

import colorsys
from PIL import Image
im = Image.open(filename)
ld = im.load()
width, height = im.size
for y in range(height):
    for x in range(width):
        r,g,b = ld[x,y]
        h,s,v = colorsys.rgb_to_hsv(r/255., g/255., b/255.)
        h = (h + -90.0/360.0) % 1.0
        s = s**0.65
        r,g,b = colorsys.hsv_to_rgb(h, s, v)
        ld[x,y] = (int(r * 255.9999), int(g * 255.9999), int(b * 255.9999))

我建议将图像转换为数组,然后应用rgb_to_hsv函数:这样可以避免双for循环,这可能会导致使用colorsys的逐像素方法速度较慢。

我建议将图像转换为数组,然后应用rgb_to_hsv函数:这样可以避免双for循环,这可能会导致使用colorsys的逐像素方法速度较慢。

类似的问题:这不一样。我想要的是旋转色调。类似的问题:它不一样。我想要的是旋转色调。看起来很完美!谢谢我将尝试它,并继续我的棕色检测!它起作用了!但是是的,有点慢。我想知道它怎么能这么快看起来很完美!谢谢我将尝试它,并继续我的棕色检测!它起作用了!但是是的,有点慢。我想知道怎样才能更快