Chris Oswald commited on
Commit
49b2bed
1 Parent(s): 745e2d8
Files changed (1) hide show
  1. SPIDER.py +22 -5
SPIDER.py CHANGED
@@ -76,13 +76,31 @@ def standardize_3D_image(
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
@@ -512,10 +530,9 @@ class SPIDER(datasets.GeneratorBasedBuilder):
512
  mask_array_standardized = np.array(mask_array_original, dtype='uint8')
513
 
514
  # Convert .mha mask to standardized numeric array
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
 
76
  if image.shape[0] < image.shape[2]:
77
  image = np.transpose(image, axes=[1, 2, 0])
78
  # Resize image
79
+ image = skimage.transform.resize(image, resize_shape)
 
80
  # Rescale to UInt8 type (required for PyArrow and PIL)
81
  image = skimage.img_as_ubyte(image)
82
  return image
83
 
84
+ def standardize_3D_mask(
85
+ mask: np.ndarray,
86
+ resize_shape: Tuple[int, int, int],
87
+ ) -> np.ndarray:
88
+ """Aligns dimensions of image to be (height, width, channels); resizes
89
+ images to values specified in resize_shape using nearest neighbor interpolation;
90
+ and rescales pixel values to Uint8."""
91
+ # Align height, width, channel dims
92
+ if mask.shape[0] < mask.shape[2]:
93
+ mask = np.transpose(mask, axes=[1, 2, 0])
94
+ # Resize mask
95
+ mask = skimage.transform.resize(
96
+ mask,
97
+ resize_shape,
98
+ order=0,
99
+ preserve_range=True,
100
+ )
101
+ # Rescale to UInt8 type (required for PyArrow and PIL)
102
+ mask = skimage.img_as_ubyte(mask)
103
+ return mask
104
 
105
  # Define constants
106
  MIN_IVD = 0
 
530
  mask_array_standardized = np.array(mask_array_original, dtype='uint8')
531
 
532
  # Convert .mha mask to standardized numeric array
533
+ mask_array_standardized = standardize_3D_mask(
534
  mask_array_standardized,
535
  resize_shape,
 
536
  )
537
 
538
  # Extract overview data corresponding to image