【发布时间】:2018-06-14 13:53:24
【问题描述】:
我是编码新手,我真的很困惑。从下面的代码中,我试图打印从 (0,0,0) 到 (255,255,255) 的 RGB 光谱中的每一种颜色,所以从技术上讲,应该有 256^3 图像打印所有颜色。我已经在下面做了它,它只适用于红色或蓝色或绿色光谱,而不是组合。我试图对打印出来的所有颜色做的是以这种格式将它们逐个像素地拼接在一起。我不想打印出所有图像,但最后得到组合版本。任何帮助将不胜感激!非常感谢您的帮助!
我想得到 3 个变量的所有组合,从 0 到 255。例如,print axis 的输出将是:
(0,0,0)
(1,0,0)
(2,0,0)
...
(255,0,0)
(0,1,0)
(0,2,0)
...
(0,255,0)
(0,0,1)
(0,0,2)
...
(0,0,255)
(1,0,1)
...
所以基本上这 3 个数字的所有不同组合直到 255。
我尝试使用下面的那个,但我想要做的有点不同,我想要的每个像素都是不同的,并通过遍历值以逐像素格式拼接在一起。
from PIL import Image
import sys
im = Image.new("RGB", (1, 1))
pix = im.load()
red=0
green=0
blue=0
j=0
while red<255 and green<255 and blue<255:
j+=1
red +=1
#green +=1
#blue+=1
for x in range(1):
for y in range(1):
axis = (red,green,blue)
pix[x,y] = axis
print axis
im.save('Test {}.png'.format(j), "PNG")
#stitching images together
images = map(Image.open, ['Test 1.png', 'Test 255.png', 'Test 100.png'])
widths, heights = zip(*(i.size for i in images))
total_width = sum(widths)
max_height = max(heights)
new_im = Image.new('RGB', (total_width, max_height))
x_offset = 0
for im in images:
new_im.paste(im, (x_offset,0))
x_offset += im.size[0]
new_im.save('test.jpg')
【问题讨论】:
标签: python colors python-imaging-library rgb