Chris Oswald
commited on
Commit
·
76cb606
1
Parent(s):
ba3659a
debugging
Browse files
SPIDER.py
CHANGED
|
@@ -170,8 +170,8 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 170 |
features = datasets.Features({
|
| 171 |
"patient_id": datasets.Value("string"),
|
| 172 |
"scan_type": datasets.Value("string"),
|
| 173 |
-
"
|
| 174 |
-
"
|
| 175 |
"image_array": datasets.Array3D(shape=image_size, dtype='float64'),
|
| 176 |
"mask_array": datasets.Array3D(shape=image_size, dtype='float64'),
|
| 177 |
"metadata": {
|
|
@@ -479,8 +479,8 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 479 |
image_path = os.path.join(paths_dict['images'], 'images', example)
|
| 480 |
image = sitk.ReadImage(image_path)
|
| 481 |
|
| 482 |
-
# Rescale image intensities to [0, 255] and cast as UInt8 type
|
| 483 |
-
image = sitk.Cast(sitk.RescaleIntensity(image), sitk.sitkUInt8)
|
| 484 |
|
| 485 |
# Convert .mha image to original size numeric array
|
| 486 |
image_array_original = sitk.GetArrayFromImage(image)
|
|
@@ -491,15 +491,14 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 491 |
resize_shape,
|
| 492 |
)
|
| 493 |
|
| 494 |
-
#
|
| 495 |
-
|
| 496 |
-
|
| 497 |
# Load .mha mask file
|
| 498 |
mask_path = os.path.join(paths_dict['masks'], 'masks', example)
|
| 499 |
mask = sitk.ReadImage(mask_path)
|
| 500 |
|
| 501 |
-
# Rescale mask intensities to [0, 255] and cast as UInt8 type
|
| 502 |
-
mask = sitk.Cast(sitk.RescaleIntensity(mask), sitk.sitkUInt8)
|
| 503 |
|
| 504 |
# Convert .mha mask to original size numeric array
|
| 505 |
mask_array_original = sitk.GetArrayFromImage(mask)
|
|
@@ -510,9 +509,6 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 510 |
resize_shape,
|
| 511 |
)
|
| 512 |
|
| 513 |
-
# Create PIL image object of original mask
|
| 514 |
-
# PIL_original_mask = PIL.Image.fromarray(mask_array_original)
|
| 515 |
-
|
| 516 |
# Extract overview data corresponding to image
|
| 517 |
image_overview = overview_dict[scan_id]
|
| 518 |
|
|
@@ -523,8 +519,8 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 523 |
return_dict = {
|
| 524 |
'patient_id':patient_id,
|
| 525 |
'scan_type':scan_type,
|
| 526 |
-
'
|
| 527 |
-
'
|
| 528 |
'image_array':image_array_standardized,
|
| 529 |
'mask_array':mask_array_standardized,
|
| 530 |
'metadata':image_overview,
|
|
|
|
| 170 |
features = datasets.Features({
|
| 171 |
"patient_id": datasets.Value("string"),
|
| 172 |
"scan_type": datasets.Value("string"),
|
| 173 |
+
"image_path": datasets.Value("string"),
|
| 174 |
+
"mask_path": datasets.Value("string"),
|
| 175 |
"image_array": datasets.Array3D(shape=image_size, dtype='float64'),
|
| 176 |
"mask_array": datasets.Array3D(shape=image_size, dtype='float64'),
|
| 177 |
"metadata": {
|
|
|
|
| 479 |
image_path = os.path.join(paths_dict['images'], 'images', example)
|
| 480 |
image = sitk.ReadImage(image_path)
|
| 481 |
|
| 482 |
+
# # Rescale image intensities to [0, 255] and cast as UInt8 type
|
| 483 |
+
# image = sitk.Cast(sitk.RescaleIntensity(image), sitk.sitkUInt8)
|
| 484 |
|
| 485 |
# Convert .mha image to original size numeric array
|
| 486 |
image_array_original = sitk.GetArrayFromImage(image)
|
|
|
|
| 491 |
resize_shape,
|
| 492 |
)
|
| 493 |
|
| 494 |
+
# NOTE: since the original array shape is not standardized, cannot return in dataset
|
| 495 |
+
|
|
|
|
| 496 |
# Load .mha mask file
|
| 497 |
mask_path = os.path.join(paths_dict['masks'], 'masks', example)
|
| 498 |
mask = sitk.ReadImage(mask_path)
|
| 499 |
|
| 500 |
+
# # Rescale mask intensities to [0, 255] and cast as UInt8 type
|
| 501 |
+
# mask = sitk.Cast(sitk.RescaleIntensity(mask), sitk.sitkUInt8)
|
| 502 |
|
| 503 |
# Convert .mha mask to original size numeric array
|
| 504 |
mask_array_original = sitk.GetArrayFromImage(mask)
|
|
|
|
| 509 |
resize_shape,
|
| 510 |
)
|
| 511 |
|
|
|
|
|
|
|
|
|
|
| 512 |
# Extract overview data corresponding to image
|
| 513 |
image_overview = overview_dict[scan_id]
|
| 514 |
|
|
|
|
| 519 |
return_dict = {
|
| 520 |
'patient_id':patient_id,
|
| 521 |
'scan_type':scan_type,
|
| 522 |
+
'image_path':image_path,
|
| 523 |
+
'mask_path':mask_path,
|
| 524 |
'image_array':image_array_standardized,
|
| 525 |
'mask_array':mask_array_standardized,
|
| 526 |
'metadata':image_overview,
|