在python中将多个图像绘制到tiff文件中

时间:2014-09-11 07:06:14

标签: python image python-imaging-library tiff

我有相同大小的多个图像,我想在tiff文件上绘制这些图像,使得一行中少于5个元素,其中心之间有一些x距离(水平沿着行) y距离(沿着列垂直)图像存储在一个文件夹中,程序应该读取图像并在tiff文件上绘制图像。

我发现这有点有用(并且更接近我的要求)http://www.astrobetter.com/plotting-to-a-file-in-python/但它正在绘制一个图表来存档。我想把图像放到我的tiff文件

我该怎么办?

1 个答案:

答案 0 :(得分:2)

我想,这是你所描述的。这是图像,只要它们具有相同的大小,您可以拥有其中的许多图像,在代码中的图像列表上配置值以更改此值。

enter image description here

这是该程序的输出:

enter image description here

这是代码:

import Image

images = ['image.jpg','image.jpg','image.jpg','image.jpg','image.jpg','image.jpg','image.jpg']

hsize = min(5,len(images))
vsize = (len(images)/5) + 1

print hsize,vsize

vspace = 10
hspace = 10

(h,w) = Image.open(images[0]).size

im = Image.new('RGB',((hsize*(h+hspace)),(vsize*(w+vspace)) ))

for i,filename in enumerate(images):
    imin = Image.open(filename).convert('RGB')
    xpos = i % hsize
    ypos = i / hsize
    print xpos,ypos
    im.paste(imin,(xpos*(h+hspace),ypos*(w+vspace)))
im.save('output.jpg')