Spaces:
Sleeping
Sleeping
Upload tiles.py
Browse files- src/tiles.py +26 -0
src/tiles.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
|
| 3 |
+
def tile_image(image, tile_size, overlap):
|
| 4 |
+
"""
|
| 5 |
+
A function to break an image into tiles
|
| 6 |
+
Args:
|
| 7 |
+
image: The image to break into tiles
|
| 8 |
+
tile_size: The size of the tiles
|
| 9 |
+
overlap: The overlap between tiles
|
| 10 |
+
Returns:
|
| 11 |
+
A list of tiles
|
| 12 |
+
"""
|
| 13 |
+
# Get the image size
|
| 14 |
+
width, height = image.size
|
| 15 |
+
|
| 16 |
+
# Create a list to store the tiles
|
| 17 |
+
tiles = []
|
| 18 |
+
|
| 19 |
+
# Loop through the image and break it into tiles
|
| 20 |
+
for x in range(0, width, tile_size - overlap):
|
| 21 |
+
for y in range(0, height, tile_size - overlap):
|
| 22 |
+
# Get the tile
|
| 23 |
+
tile = image.crop((x, y, x + tile_size, y + tile_size))
|
| 24 |
+
tiles.append(tile)
|
| 25 |
+
|
| 26 |
+
return tiles
|