gpt4 book ai didi

python PIL : shift the hue and saturation

转载 作者:太空宇宙 更新时间:2023-11-04 08:09:46 25 4
gpt4 key购买 nike

在 GIMP 中,我可以轻松地改变色调和饱和度。例如下图是原图和色相-90、饱和度100后的最终效果。

我如何继续从 Python PIL 获得相同的结果?

原图

original picture

最终图片

final picture

最佳答案

您可以结合使用 colorsys 模块和 PIL 来完成它,但是速度有点慢。 colorsys 允许您将颜色空间更改为 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))

enter image description here

关于 python PIL : shift the hue and saturation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24874765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com