Chris Oswald
commited on
Commit
·
745e2d8
1
Parent(s):
cbcc262
debugging
Browse files
SPIDER.py
CHANGED
@@ -66,7 +66,8 @@ def subset_file_list(all_files: List[str], subset_ids: Set[int]):
|
|
66 |
|
67 |
def standardize_3D_image(
|
68 |
image: np.ndarray,
|
69 |
-
resize_shape: Tuple[int, int, int]
|
|
|
70 |
) -> np.ndarray:
|
71 |
"""Aligns dimensions of image to be (height, width, channels); resizes
|
72 |
images to values specified in resize_shape; and rescales pixel values
|
@@ -75,12 +76,14 @@ def standardize_3D_image(
|
|
75 |
if image.shape[0] < image.shape[2]:
|
76 |
image = np.transpose(image, axes=[1, 2, 0])
|
77 |
# Resize image
|
78 |
-
|
|
|
79 |
# Rescale to UInt8 type (required for PyArrow and PIL)
|
80 |
image = skimage.img_as_ubyte(image)
|
81 |
return image
|
82 |
|
83 |
|
|
|
84 |
# Define constants
|
85 |
MIN_IVD = 0
|
86 |
MAX_IVD = 9
|
@@ -494,6 +497,7 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
494 |
image_array_standardized = standardize_3D_image(
|
495 |
image_array_original,
|
496 |
resize_shape,
|
|
|
497 |
)
|
498 |
|
499 |
# Load .mha mask file
|
@@ -511,6 +515,7 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
511 |
mask_array_standardized = standardize_3D_image(
|
512 |
mask_array_standardized,
|
513 |
resize_shape,
|
|
|
514 |
)
|
515 |
|
516 |
# Extract overview data corresponding to image
|
|
|
66 |
|
67 |
def standardize_3D_image(
|
68 |
image: np.ndarray,
|
69 |
+
resize_shape: Tuple[int, int, int],
|
70 |
+
nearest_neighbor_interpolation: bool = False,
|
71 |
) -> np.ndarray:
|
72 |
"""Aligns dimensions of image to be (height, width, channels); resizes
|
73 |
images to values specified in resize_shape; and rescales pixel values
|
|
|
76 |
if image.shape[0] < image.shape[2]:
|
77 |
image = np.transpose(image, axes=[1, 2, 0])
|
78 |
# Resize image
|
79 |
+
order = 0 if nearest_neighbor_interpolation else 1
|
80 |
+
image = skimage.transform.resize(image, resize_shape, order=order)
|
81 |
# Rescale to UInt8 type (required for PyArrow and PIL)
|
82 |
image = skimage.img_as_ubyte(image)
|
83 |
return image
|
84 |
|
85 |
|
86 |
+
|
87 |
# Define constants
|
88 |
MIN_IVD = 0
|
89 |
MAX_IVD = 9
|
|
|
497 |
image_array_standardized = standardize_3D_image(
|
498 |
image_array_original,
|
499 |
resize_shape,
|
500 |
+
nearest_neighbor_interpolation=False,
|
501 |
)
|
502 |
|
503 |
# Load .mha mask file
|
|
|
515 |
mask_array_standardized = standardize_3D_image(
|
516 |
mask_array_standardized,
|
517 |
resize_shape,
|
518 |
+
nearest_neighbor_interpolation=True,
|
519 |
)
|
520 |
|
521 |
# Extract overview data corresponding to image
|