You can handle RGB channels as a single variable color
. So you can avoid some conditions and make everything easy.
And, you may change your loop for count in range(9)
into for factor in [0.1, 0.5, 0.9]
and for channel in range(3)
. count
is meaningless in the loop. But factor
and channel
are useful.
from PIL import Image
def convert_color(factor, channel):
def convert(color):
return (
*color[:channel],
int(color[channel] * factor),
*color[channel + 1:]
)
return convert
pic = Image.open('image.png').convert('RGB')
processed = []
for factor in [0.1, 0.5, 0.9]: # factor to multiple
for channel in range(3): # which channel
new_pic = Image.new('RGB', pic.size)
new_pic.putdata(list(map(
convert_color(factor, channel),
pic.getdata()
)))
processed.append(new_pic)
new_pic.save(f'image{len(processed)}.png')