from PIL import Image
import numpy as np
# 创建一个随机的三维数组
array_3d = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
# 在上面的代码中,我们首先导入了numpy库,并使用np.random.randint()函数创建了一个随机的三维数组。
# 这个数组的大小是(100, 100, 3),表示图像的宽度和高度都是100,而通道数为3(对应于RGB颜色空间)。我
# 们还指定了数组的数据类型为np.uint8,这是表示图像像素值的常见数据类型。
# 将三维数组array_3d转换成一个图像对象image
image = Image.fromarray(array_3d)
# 显示图像,我们可以使用image.show()方法。
image.show()
# 保存图像,我们可以使用image.save()方法。
image.save("output.png")