Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
PIL转换图像';s色调,然后用Python保存_Python_Python Imaging Library - Fatal编程技术网

PIL转换图像';s色调,然后用Python保存

PIL转换图像';s色调,然后用Python保存,python,python-imaging-library,Python,Python Imaging Library,我用PIL加载和保存图像很好,但我似乎无法改变给定图像的“整体”色调~谷歌在这里给出了一个答案,有点像是numpy模块,但这不是我的选择 它应该很简单,给定一个带有alpha的灰色图像,我想它是色调红色的我想你想要一个单色图像。这是真的吗 现在还不清楚你想用现有的波段(阿尔法和灰度/级别)做什么。是否希望alpha保持alpha,灰度变为红色饱和度?你想让阿尔法变成你的红色饱和度吗?你希望灰度是图像的亮度,而阿尔法是饱和度吗 编辑: 我已经根据您的评论更改了输出。您希望灰度带中最暗的阴影表示完全

我用PIL加载和保存图像很好,但我似乎无法改变给定图像的“整体”色调~谷歌在这里给出了一个答案,有点像是numpy模块,但这不是我的选择


它应该很简单,给定一个带有alpha的灰色图像,我想它是色调红色的

我想你想要一个单色图像。这是真的吗

现在还不清楚你想用现有的波段(阿尔法和灰度/级别)做什么。是否希望alpha保持alpha,灰度变为红色饱和度?你想让阿尔法变成你的红色饱和度吗?你希望灰度是图像的亮度,而阿尔法是饱和度吗

编辑: 我已经根据您的评论更改了输出。您希望灰度带中最暗的阴影表示完全饱和的红色,最浅的灰色表示白色(换句话说,所有颜色都完全饱和)。您还表示希望在输出中将alpha保留为alpha。我也做了改变

通过一些频带交换,这是可能的:

import Image
# get an image that is greyscale with alpha
i = Image.open('hsvwheel.png').convert('LA')
# get the two bands
L,A = i.split()
# a fully saturated band 
S, = Image.new('L', i.size, 255).split()
# re-combine the bands
# this keeps tha alpha channel in the new image
i2 = Image.merge('RGBA', (S,L,L,A))  
# save
i2.save('test.png')

我想你需要单色图像。这是真的吗

现在还不清楚你想用现有的波段(阿尔法和灰度/级别)做什么。是否希望alpha保持alpha,灰度变为红色饱和度?你想让阿尔法变成你的红色饱和度吗?你希望灰度是图像的亮度,而阿尔法是饱和度吗

编辑: 我已经根据您的评论更改了输出。您希望灰度带中最暗的阴影表示完全饱和的红色,最浅的灰色表示白色(换句话说,所有颜色都完全饱和)。您还表示希望在输出中将alpha保留为alpha。我也做了改变

通过一些频带交换,这是可能的:

import Image
# get an image that is greyscale with alpha
i = Image.open('hsvwheel.png').convert('LA')
# get the two bands
L,A = i.split()
# a fully saturated band 
S, = Image.new('L', i.size, 255).split()
# re-combine the bands
# this keeps tha alpha channel in the new image
i2 = Image.merge('RGBA', (S,L,L,A))  
# save
i2.save('test.png')

尼斯:)您还可以在最后一次合并中包含
A
,以保留alpha通道。@Sven,是的,如何保留alpha?@保罗-这太棒了!是的,我在寻找一些像Photoshop的“色调”调整一样的东西,拍摄一张去饱和(灰度)的图像,你可以只应用一个红色的色调,例如,它会在较暗的灰色区域显示出较深的红色,浅灰色区域中的粉红色或浅红色:)您还可以在上次合并中包含
A
,以保留alpha通道。@Sven,是的,如何保留alpha?@保罗-这太棒了!是的,我正在寻找一些像Photoshop的“色调”调整一样的东西,拍摄一张去饱和(灰度)的图像,你可以只应用一个红色的色调,例如,在灰色的较暗区域它会变成深红色,在灰色的较亮区域它会变成粉红色或浅红色