MCPcopy Create free account
hub / github.com/NVlabs/SPADE / tile_images

Function tile_images

util/util.py:40–59  ·  view source on GitHub ↗

Code borrowed from https://stackoverflow.com/questions/26521365/cleanly-tile-numpy-array-of-images-stored-in-a-flattened-1d-format/26521997

(imgs, picturesPerRow=4)

Source from the content-addressed store, hash-verified

38
39
40def tile_images(imgs, picturesPerRow=4):
41 """ Code borrowed from
42 https://stackoverflow.com/questions/26521365/cleanly-tile-numpy-array-of-images-stored-in-a-flattened-1d-format/26521997
43 """
44
45 # Padding
46 if imgs.shape[0] % picturesPerRow == 0:
47 rowPadding = 0
48 else:
49 rowPadding = picturesPerRow - imgs.shape[0] % picturesPerRow
50 if rowPadding > 0:
51 imgs = np.concatenate([imgs, np.zeros((rowPadding, *imgs.shape[1:]), dtype=imgs.dtype)], axis=0)
52
53 # Tiling Loop (The conditionals are not necessary anymore)
54 tiled = []
55 for i in range(0, imgs.shape[0], picturesPerRow):
56 tiled.append(np.concatenate([imgs[j] for j in range(i, i + picturesPerRow)], axis=1))
57
58 tiled = np.concatenate(tiled, axis=0)
59 return tiled
60
61
62# Converts a Tensor into a Numpy array

Callers 2

tensor2imFunction · 0.85
tensor2labelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected