Function used to slice the main panorama image into the desired tiles.
Images are saved to be used for inference later.
| Parameters: |
-
img
(ndarray)
–
-
dir
(str)
–
Directory to save files in.
-
img_size
(int, default:
2000
)
–
Size of tile images in pixels - square tiles assumed. Defaults to 2000.
-
overlap
(int, default:
100
)
–
Overlap between tiles. Defaults to 100.
-
slicing
(bool, default:
True
)
–
Set False if you don't want to slice image, but just figure out th (n,m) values. Defaults to True.
|
| Returns: |
-
–
n, m: grid sizes for tiling post-inference.
|
Source code in MinDet/slicing.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 | def img_slice(img, dir, img_size = 2000, overlap = 100, slicing = True):
"""Function used to slice the main panorama image into the desired tiles.
Images are saved to be used for inference later.
Args:
img (ndarray): Panorama image
dir (str): Directory to save files in.
img_size (int, optional): Size of tile images in pixels - square tiles assumed. Defaults to 2000.
overlap (int, optional): Overlap between tiles. Defaults to 100.
slicing (bool, optional): Set False if you don't want to slice image, but just figure out th (n,m) values. Defaults to True.
Returns:
n, m: grid sizes for tiling post-inference.
"""
n = int((img.shape[0]-overlap)/(img_size - overlap))+1
m = int((img.shape[1]-overlap)/(img_size - overlap))+1
step_size = img_size - overlap
if slicing == True:
for i in range(n):
for j in range(m):
x_start = i*step_size
y_start = j*step_size
if (x_start+img_size) > img.shape[0]:
x_start = img.shape[0]-img_size
if (y_start+img_size) > img.shape[1]:
y_start = img.shape[1]-img_size
else:
pass
temp_slice = img[x_start:x_start+img_size,
y_start:y_start +img_size,
:]
if os.path.exists(dir + "/imgs") == True:
pass
else:
os.makedirs(dir + "/imgs")
cv2.imwrite( dir + "/imgs/image_" + str(i) + "_" + str(j) + ".jpg", temp_slice, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
else:
pass
return n,m
|