Function iatiling

Synopse

Create a large 2D image from a list of smaller images.

  • g = iatiling(f_list,w)
    • Output - g: ndarray, 2D, uint8. Mosaic image built from list of images
    • Input
      • f_list: List of ndarray, 2D, images.
      • w: size of the output image. The width is w and the height is multiple values of w.

Description

The iatiling function builds an image with all the images in the list of input images. The images are inserted from top to bottom and left to right. The output image size is first set at (w,w) and when the height is reached, the output image is increased in height by chunks of w.

Function Code

01. import numpy as np
02. def iatiling(f, w):
03.   H = Hold = w
04.   g = np.zeros((H,w),'uint8')
05.   ih = iw = 0
06.   himax = 0
07.   for i in range(len(f)):
08.     hi,wi = f[i].shape
09.     if iw+wi > w:  # test if reach width
10.       iw = 0
11.       ih += himax + 1
12.       himax = 0
13.     if ih+hi > H:  # at any time test if reach height
14.       H += w
15.       g1 = np.zeros((H,w),'uint8')
16.       g1[:Hold,:] = g
17.       g = g1
18.       Hold = H
19.     g[ih:ih+hi, iw:iw+wi] = f[i] # insert another image
20.     iw += wi + 1
21.     himax = max(himax,hi)
22.   return g

Examples

From number plates:

01. import ia636 as ia
02. 
03. f = adreadgray('cameraman.tif')
04. li = []
05. dh,dw = 15,10
06. for i in arange(10):
07.     dw += 1
08.     dh += 2
09.     for j in arange(10):
10.         li.append(f[j*dh:j*dh+dh,i*dw:i*dw+dw])
11. g = ia.iatiling(li, 400)
12. adshow(g,title='w=400')
13. g = ia.iatiling(li, 200)
14. adshow(g,title='w=200')

w=400

w=200

See Also

Contributions

  • Roberto Lotufo, 9may2013: initial function.