Prepares a single grid of images. Useful for visualization purposes.
(images: List[PIL.Image.Image], rows: int, cols: int, resize: int = None)
| 51 | |
| 52 | |
| 53 | def make_image_grid(images: List[PIL.Image.Image], rows: int, cols: int, resize: int = None) -> PIL.Image.Image: |
| 54 | """ |
| 55 | Prepares a single grid of images. Useful for visualization purposes. |
| 56 | """ |
| 57 | assert len(images) == rows * cols |
| 58 | |
| 59 | if resize is not None: |
| 60 | images = [img.resize((resize, resize)) for img in images] |
| 61 | |
| 62 | w, h = images[0].size |
| 63 | grid = Image.new("RGB", size=(cols * w, rows * h)) |
| 64 | |
| 65 | for i, img in enumerate(images): |
| 66 | grid.paste(img, box=(i % cols * w, i // cols * h)) |
| 67 | return grid |
no test coverage detected