Code borrowed from https://stackoverflow.com/questions/26521365/cleanly-tile-numpy-array-of-images-stored-in-a-flattened-1d-format/26521997
(imgs, picturesPerRow=4)
| 38 | |
| 39 | |
| 40 | def 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 |
no outgoing calls
no test coverage detected