使用 PIL 进行 RGB 处理 - 如何拍摄单张图像并生成具有不同 RGB 值的图像?

RGB processing with PIL - How to take a single image and produce images with different values RGB?

我想拍摄一张照片,然后将其转换为 9 张不同的图像,然后添加到列表中。 我想把这张单图,然后把R值改大一点,再把R值改一半,最后把R改小一点。

虽然我正在努力让它发挥作用。 我的逻辑循环似乎不起作用,我的图像也没有被修改。 任何帮助表示赞赏。

from PIL import Image

# Set the file and open it
file = "Final/charlie.png"
#pic = Image.open(file)

#Convert to RGB, so we dont have to deal with the alpha channel
#pic = pic.convert('RGB')
images = []
count = 0


#Image processing for lage change
def image_processing0(a):
    c = int(a / 10)
    return c

#Create PixelMap
count = 0
while count <3:
    pic = Image.open(file)
    pic = pic.convert('RGB')
    for x in range(pic.size[0]):
            for y in range(pic.size[1]):
                r,g,b = pic.getpixel((x,y))

#Check the count and use logic to appy the processing to the corect channel               
                if count == 1:
                    image_processing0(r)
                    pic.putpixel((x,y),(r,g,b))
                elif count == 2:
                    image_processing0(g)
                    pic.putpixel((x,y),(r,g,b))
                else:
                    image_processing0(b)
                    pic.putpixel((x,y),(r,g,b))
                    
    images.append(pic)  
    count+=1

您忘记将 image_processing0 的 return 分配给 r, g, b

改变这个:

if count == 1:
    image_processing0(r)
    pic.putpixel((x,y),(r,g,b))
elif count == 2:
    image_processing0(g)
    pic.putpixel((x,y),(r,g,b))
else:
    image_processing0(b)
    pic.putpixel((x,y),(r,g,b))

收件人:

if count == 1:
    r = image_processing0(r)
    pic.putpixel((x,y),(r,g,b))
elif count == 2:
    g = image_processing0(g)
    pic.putpixel((x,y),(r,g,b))
else:
    b = image_processing0(b)
    pic.putpixel((x,y),(r,g,b))