For the [ALMA Summer Science Exhibition blog] I wanted to make a [big mosaic] of all the images taken – you’ll probably see this on the [post below] (unless its fallen off the bottom of the page!). To do this was really quite straight forward using python (well matplotlib mostly).
The below script takes in a list of png files and then setups a canvas – something I’d already figured out the dimensions for via the figure size of 12 by 12 inches and a 400dpi – that gives me 400 pixels for each inch and nicely each image is a 400×400 pixel square. I’d also already figured out the loop limits that were required to get all of my images in (if I get chance I might make these command line options and package this up as a little tool but I’m sure many better ones already exist – this is more a quick and dirty way of doing this).
import matplotlib.pyplot as plt
import numpy as np
from scipy import ndimage
xtemp = os.popen("ls *png") #all files
xtemp2 = (xtemp.read().split('n'))
files = len(xtemp2)-1 #number of files.
stepsize = 400 #this is the image size in x,y
fig = plt.figure(num=None, figsize=(12, 12), facecolor='k', edgecolor='none')
k = 0
j = 0
i = 0
while k< 5000:
j = 0
while j < 5000:
im = Image.open(xtemp2[i])
im = np.array(im).astype(np.float) / 255
#im = ndimage.rotate(im, 90) #if we need to rotate
fig.figimage(im, k, j) #, zorder=i)
print k, j, i
plt.subplots_adjust(left=0.00, right=1.0, top=0.9, bottom=0.0)
fig.savefig('outputprint.png',figsize=(12, 12),dpi=400, facecolor='k', edgecolor='k')