Chris Oswald
commited on
Commit
·
da94d71
1
Parent(s):
b4f24a3
converted to sequence of images
Browse files
SPIDER.py
CHANGED
|
@@ -66,11 +66,11 @@ 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
|
| 70 |
) -> np.ndarray:
|
| 71 |
"""Aligns dimensions of image to be (height, width, channels); resizes
|
| 72 |
-
images to values specified in resize_shape; and rescales
|
| 73 |
-
to Uint8."""
|
| 74 |
# Align height, width, channel dims
|
| 75 |
if image.shape[0] < image.shape[2]:
|
| 76 |
image = np.transpose(image, axes=[1, 2, 0])
|
|
@@ -519,6 +519,16 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 519 |
image_array_original,
|
| 520 |
resize_shape,
|
| 521 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
|
| 523 |
# Load .mha mask file
|
| 524 |
mask_path = os.path.join(paths_dict['masks'], 'masks', example)
|
|
@@ -537,6 +547,16 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 537 |
resize_shape,
|
| 538 |
)
|
| 539 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
# Extract overview data corresponding to image
|
| 541 |
image_overview = overview_dict[scan_id]
|
| 542 |
|
|
@@ -547,8 +567,8 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 547 |
return_dict = {
|
| 548 |
'patient_id':patient_id,
|
| 549 |
'scan_type':scan_type,
|
| 550 |
-
'image':
|
| 551 |
-
'mask':
|
| 552 |
'image_path':image_path,
|
| 553 |
'mask_path':mask_path,
|
| 554 |
'metadata':image_overview,
|
|
|
|
| 66 |
|
| 67 |
def standardize_3D_image(
|
| 68 |
image: np.ndarray,
|
| 69 |
+
resize_shape: Tuple[int, int],
|
| 70 |
) -> np.ndarray:
|
| 71 |
"""Aligns dimensions of image to be (height, width, channels); resizes
|
| 72 |
+
images to height/width values specified in resize_shape; and rescales
|
| 73 |
+
pixel values to Uint8."""
|
| 74 |
# Align height, width, channel dims
|
| 75 |
if image.shape[0] < image.shape[2]:
|
| 76 |
image = np.transpose(image, axes=[1, 2, 0])
|
|
|
|
| 519 |
image_array_original,
|
| 520 |
resize_shape,
|
| 521 |
)
|
| 522 |
+
|
| 523 |
+
# Split image array into sequence of 2D images
|
| 524 |
+
split_len = image_array_standardized.shape[-1]
|
| 525 |
+
images_seq = [
|
| 526 |
+
np.squeeze(arr) for arr in np.split(
|
| 527 |
+
image_array_standardized,
|
| 528 |
+
split_len,
|
| 529 |
+
axis=-1,
|
| 530 |
+
)
|
| 531 |
+
]
|
| 532 |
|
| 533 |
# Load .mha mask file
|
| 534 |
mask_path = os.path.join(paths_dict['masks'], 'masks', example)
|
|
|
|
| 547 |
resize_shape,
|
| 548 |
)
|
| 549 |
|
| 550 |
+
# Split mask array into sequence of 2D images
|
| 551 |
+
split_len = mask_array_standardized.shape[-1]
|
| 552 |
+
masks_seq = [
|
| 553 |
+
np.squeeze(arr) for arr in np.split(
|
| 554 |
+
mask_array_standardized,
|
| 555 |
+
split_len,
|
| 556 |
+
axis=-1,
|
| 557 |
+
)
|
| 558 |
+
]
|
| 559 |
+
|
| 560 |
# Extract overview data corresponding to image
|
| 561 |
image_overview = overview_dict[scan_id]
|
| 562 |
|
|
|
|
| 567 |
return_dict = {
|
| 568 |
'patient_id':patient_id,
|
| 569 |
'scan_type':scan_type,
|
| 570 |
+
'image':images_seq,
|
| 571 |
+
'mask':masks_seq,
|
| 572 |
'image_path':image_path,
|
| 573 |
'mask_path':mask_path,
|
| 574 |
'metadata':image_overview,
|