Chris Oswald
commited on
Commit
•
7ed1b1f
1
Parent(s):
642a1ea
debugging
Browse files
SPIDER.py
CHANGED
@@ -44,15 +44,16 @@ def subset_file_list(all_files: List[str], subset_ids: Set[int]):
|
|
44 |
|
45 |
def standardize_3D_image(
|
46 |
image: np.ndarray,
|
47 |
-
resize_shape: Tuple[int, int
|
48 |
) -> np.ndarray:
|
49 |
"""Aligns dimensions of image to be (height, width, channels) and resizes
|
50 |
-
images to values specified in resize_shape
|
|
|
51 |
# Align height, width, channel dims
|
52 |
if image.shape[0] < image.shape[2]:
|
53 |
image = np.transpose(image, axes=[1, 2, 0])
|
54 |
# Resize image
|
55 |
-
image = skimage.transform.resize(image, resize_shape)
|
56 |
# Rescale to UInt8 type
|
57 |
image = skimage.img_as_ubyte(image)
|
58 |
return image
|
@@ -63,7 +64,7 @@ N_PATIENTS = 218
|
|
63 |
MIN_IVD = 0
|
64 |
MAX_IVD = 9
|
65 |
DEFAULT_SCAN_TYPES = ['t1', 't2', 't2_SPACE']
|
66 |
-
DEFAULT_RESIZE = (512, 512
|
67 |
|
68 |
_CITATION = """\
|
69 |
@misc{vandergraaf2023lumbar,
|
@@ -193,8 +194,8 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
193 |
features = datasets.Features({
|
194 |
"patient_id": datasets.Value("string"),
|
195 |
"scan_type": datasets.Value("string"),
|
196 |
-
"image": datasets.
|
197 |
-
"mask": datasets.
|
198 |
# "image": datasets.Array3D(shape=self.config.resize_shape, dtype='uint8'),
|
199 |
# "mask": datasets.Array3D(shape=self.config.resize_shape, dtype='uint8'),
|
200 |
"image_path": datasets.Value("string"),
|
@@ -519,8 +520,8 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
519 |
return_dict = {
|
520 |
'patient_id':patient_id,
|
521 |
'scan_type':scan_type,
|
522 |
-
'
|
523 |
-
'
|
524 |
'image_path':image_path,
|
525 |
'mask_path':mask_path,
|
526 |
'metadata':image_overview,
|
|
|
44 |
|
45 |
def standardize_3D_image(
|
46 |
image: np.ndarray,
|
47 |
+
resize_shape: Tuple[int, int]
|
48 |
) -> np.ndarray:
|
49 |
"""Aligns dimensions of image to be (height, width, channels) and resizes
|
50 |
+
images to values specified in resize_shape (note that original channels
|
51 |
+
are preserved)."""
|
52 |
# Align height, width, channel dims
|
53 |
if image.shape[0] < image.shape[2]:
|
54 |
image = np.transpose(image, axes=[1, 2, 0])
|
55 |
# Resize image
|
56 |
+
image = skimage.transform.resize(image, resize_shape) # Preserves original channels
|
57 |
# Rescale to UInt8 type
|
58 |
image = skimage.img_as_ubyte(image)
|
59 |
return image
|
|
|
64 |
MIN_IVD = 0
|
65 |
MAX_IVD = 9
|
66 |
DEFAULT_SCAN_TYPES = ['t1', 't2', 't2_SPACE']
|
67 |
+
DEFAULT_RESIZE = (512, 512)
|
68 |
|
69 |
_CITATION = """\
|
70 |
@misc{vandergraaf2023lumbar,
|
|
|
194 |
features = datasets.Features({
|
195 |
"patient_id": datasets.Value("string"),
|
196 |
"scan_type": datasets.Value("string"),
|
197 |
+
"image": datasets.Array3D(dtype='uint8'),
|
198 |
+
"mask": datasets.Array3D(dtype='uint8'),
|
199 |
# "image": datasets.Array3D(shape=self.config.resize_shape, dtype='uint8'),
|
200 |
# "mask": datasets.Array3D(shape=self.config.resize_shape, dtype='uint8'),
|
201 |
"image_path": datasets.Value("string"),
|
|
|
520 |
return_dict = {
|
521 |
'patient_id':patient_id,
|
522 |
'scan_type':scan_type,
|
523 |
+
'image_array':image_array_standardized,
|
524 |
+
'mask_array':mask_array_standardized,
|
525 |
'image_path':image_path,
|
526 |
'mask_path':mask_path,
|
527 |
'metadata':image_overview,
|