Add tile_count property to Grid

This commit is contained in:
Aarni Koskela 2023-12-27 11:01:45 +02:00
parent 7aa27b000a
commit 12c6f37f8e
1 changed files with 7 additions and 1 deletions

View File

@ -61,7 +61,13 @@ def image_grid(imgs, batch_size=1, rows=None):
return grid return grid
Grid = namedtuple("Grid", ["tiles", "tile_w", "tile_h", "image_w", "image_h", "overlap"]) class Grid(namedtuple("_Grid", ["tiles", "tile_w", "tile_h", "image_w", "image_h", "overlap"])):
@property
def tile_count(self) -> int:
"""
The total number of tiles in the grid.
"""
return sum(len(row[2]) for row in self.tiles)
def split_grid(image: Image.Image, tile_w: int = 512, tile_h: int = 512, overlap: int = 64) -> Grid: def split_grid(image: Image.Image, tile_w: int = 512, tile_h: int = 512, overlap: int = 64) -> Grid: