mckabue commited on
Commit
cce0090
·
verified ·
1 Parent(s): 8603a32

RE_UPLOAD-REBUILD-RESTART

Browse files
Files changed (1) hide show
  1. utils/split_image.py +19 -0
utils/split_image.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from typing import Literal
3
+
4
+ def split_image(image: np.ndarray, width_parts: int, height_parts: int, result: Literal['np.ndarray', 'bboxes'] = 'np.ndarray'):
5
+ tile_width = image.shape[0] // width_parts
6
+ tile_height = image.shape[1] // height_parts
7
+ for height in range(height_parts):
8
+ for width in range(width_parts):
9
+ width_start = width * tile_width
10
+ width_end = tile_width * (width + 1) if (width + 1) < width_parts else image.shape[0]
11
+ height_start = height * tile_height
12
+ height_end = tile_height * (height + 1) if (height + 1) < height_parts else image.shape[1]
13
+ if result == 'np.ndarray':
14
+ # np.ndarray(height, width, channels)
15
+ yield image[height_start:height_end, width_start:width_end]
16
+ else:
17
+ # Both sets of boxes are expected to be in ``(x1, y1, x2, y2)`` format with ``0 <= x1 < x2`` and ``0 <= y1 < y2``.
18
+ yield (width_start, height_start, width_end, height_end)
19
+