Spaces:
Sleeping
Sleeping
Commit
·
3c5f9a0
1
Parent(s):
b8c299e
added pad_to_square to io_utils.py
Browse files- io_utils.py +25 -1
io_utils.py
CHANGED
@@ -2,13 +2,37 @@
|
|
2 |
# This files contains OSAIL utils to read and write files.
|
3 |
################################################################################
|
4 |
|
5 |
-
from .data import pad_to_square
|
6 |
import copy
|
7 |
import monai as mn
|
8 |
import numpy as np
|
9 |
import os
|
10 |
import skimage
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
################################################################################
|
13 |
# -F: load_image
|
14 |
|
|
|
2 |
# This files contains OSAIL utils to read and write files.
|
3 |
################################################################################
|
4 |
|
|
|
5 |
import copy
|
6 |
import monai as mn
|
7 |
import numpy as np
|
8 |
import os
|
9 |
import skimage
|
10 |
|
11 |
+
################################################################################
|
12 |
+
# -F: pad_to_square
|
13 |
+
|
14 |
+
def pad_to_square(image):
|
15 |
+
"""A function to pad an image to square shape with zero pixels.
|
16 |
+
|
17 |
+
Args:
|
18 |
+
image (np.ndarray): the input image array.
|
19 |
+
|
20 |
+
Returns:
|
21 |
+
np.ndarray: the padded image array.
|
22 |
+
"""
|
23 |
+
height, width = image.shape
|
24 |
+
if height < width:
|
25 |
+
padded_image = np.zeros((width, width))
|
26 |
+
delta = (width - height) // 2
|
27 |
+
padded_image[delta:height+delta, :] = image
|
28 |
+
image = padded_image
|
29 |
+
elif height > width:
|
30 |
+
padded_image = np.zeros((height, height))
|
31 |
+
delta = (height - width) // 2
|
32 |
+
padded_image[:, delta:width+delta] = image
|
33 |
+
image = padded_image
|
34 |
+
return image
|
35 |
+
|
36 |
################################################################################
|
37 |
# -F: load_image
|
38 |
|