小编TNT*_*rst的帖子

你如何在python中生成每个像素都是随机颜色的图像

我正在尝试为每个像素制作一个具有随机颜色的图像,然后打开一个窗口来查看图像。

import PIL, random
import matplotlib.pyplot as plt 
import os.path  
import PIL.ImageDraw            
from PIL import Image, ImageDraw, ImageFilter


im = Image.new("RGB", (300,300))

for r in range(0,300):
    for c in range(0,300):
        re = random.randint(0, 255)
        gr = random.randint(0, 255)
        bl = random.randint(0, 255)
        im[r][c]=[re,gr,bl]
im.show()

     14         bl = random.randint(0, 255)
---> 15         im[r][c]=[re,gr,bl]
     16 im.show()
TypeError: 'Image' object does not support indexing 
Run Code Online (Sandbox Code Playgroud)

python random image colors image-processing

2
推荐指数
1
解决办法
3437
查看次数

标签 统计

colors ×1

image ×1

image-processing ×1

python ×1

random ×1