Chris Oswald commited on
Commit
5a56741
1 Parent(s): 48bacc5

added mask array

Browse files
Files changed (1) hide show
  1. SPIDER.py +12 -16
SPIDER.py CHANGED
@@ -168,9 +168,9 @@ class SPIDER(datasets.GeneratorBasedBuilder):
168
  "patient_id": datasets.Value("string"),
169
  "scan_type": datasets.Value("string"),
170
  # "raw_image": datasets.Image(),
171
- "image_array": datasets.Array3D(shape=image_size, dtype='float32'),
172
  # "raw_mask": datasets.Image(),
173
- "mask_array": datasets.Array3D(shape=image_size, dtype='float32'),
174
  "metadata": {
175
  "num_vertebrae": datasets.Value(dtype="string"), #TODO: more specific types
176
  "num_discs": datasets.Value(dtype="string"),
@@ -289,10 +289,6 @@ class SPIDER(datasets.GeneratorBasedBuilder):
289
  resize_shape: Tuple[int, int, int],
290
  validate_share: float = 0.3,
291
  test_share: float = 0.2,
292
- raw_image: bool = True,
293
- numeric_array: bool = True,
294
- metadata: bool = True,
295
- rad_gradings: bool = True,
296
  random_seed: int = 9999,
297
  ) -> Tuple[str, Dict]:
298
  """
@@ -312,13 +308,6 @@ class SPIDER(datasets.GeneratorBasedBuilder):
312
  test_share: float indicating share of data to use for testing;
313
  must be in range (0.0, 1.0); note that training share is
314
  calculated as (1 - validate_share - test_share)
315
- raw_image: indicates whether to include .mha image file in example
316
- numeric_array: indicates whether to include numpy numeric array of
317
- image in example
318
- metadata: indicates whether to include patient and scanner metadata
319
- with image example
320
- rad_gradings: indicates whether to include patient's radiological
321
- gradings with image example
322
 
323
  Yields
324
  Tuple (unique patient-scan ID, dict of
@@ -483,7 +472,7 @@ class SPIDER(datasets.GeneratorBasedBuilder):
483
  patient_id = scan_id.split('_')[0]
484
  scan_type = '_'.join(scan_id.split('_')[1:])
485
 
486
- # Load .mha file
487
  image_path = os.path.join(paths_dict['images'], 'images', example)
488
  image = sitk.ReadImage(image_path)
489
 
@@ -492,8 +481,15 @@ class SPIDER(datasets.GeneratorBasedBuilder):
492
  sitk.GetArrayFromImage(image), resize_shape
493
  )
494
 
495
- #TODO: load mask file and numeric array
 
 
496
 
 
 
 
 
 
497
  # Extract overview data corresponding to image
498
  image_overview = overview_dict[scan_id]
499
 
@@ -507,7 +503,7 @@ class SPIDER(datasets.GeneratorBasedBuilder):
507
  'raw_image':None, #TODO
508
  'raw_mask':None, #TODO
509
  'image_array':image_array,
510
- 'mask_array':None, #TODO
511
  'metadata':image_overview,
512
  'rad_gradings':patient_grades_dict,
513
  }
 
168
  "patient_id": datasets.Value("string"),
169
  "scan_type": datasets.Value("string"),
170
  # "raw_image": datasets.Image(),
171
+ "image_array": datasets.Array3D(shape=image_size, dtype='float64'),
172
  # "raw_mask": datasets.Image(),
173
+ "mask_array": datasets.Array3D(shape=image_size, dtype='float64'),
174
  "metadata": {
175
  "num_vertebrae": datasets.Value(dtype="string"), #TODO: more specific types
176
  "num_discs": datasets.Value(dtype="string"),
 
289
  resize_shape: Tuple[int, int, int],
290
  validate_share: float = 0.3,
291
  test_share: float = 0.2,
 
 
 
 
292
  random_seed: int = 9999,
293
  ) -> Tuple[str, Dict]:
294
  """
 
308
  test_share: float indicating share of data to use for testing;
309
  must be in range (0.0, 1.0); note that training share is
310
  calculated as (1 - validate_share - test_share)
 
 
 
 
 
 
 
311
 
312
  Yields
313
  Tuple (unique patient-scan ID, dict of
 
472
  patient_id = scan_id.split('_')[0]
473
  scan_type = '_'.join(scan_id.split('_')[1:])
474
 
475
+ # Load .mha image file
476
  image_path = os.path.join(paths_dict['images'], 'images', example)
477
  image = sitk.ReadImage(image_path)
478
 
 
481
  sitk.GetArrayFromImage(image), resize_shape
482
  )
483
 
484
+ # Load .mha mask file
485
+ mask_path = os.path.join(paths_dict['masks'], 'masks', example)
486
+ mask = sitk.ReadImage(mask_path)
487
 
488
+ # Convert .mha mask to standardized numeric array
489
+ mask_array = standardize_3D_image(
490
+ sitk.GetArrayFromImage(mask), resize_shape
491
+ )
492
+
493
  # Extract overview data corresponding to image
494
  image_overview = overview_dict[scan_id]
495
 
 
503
  'raw_image':None, #TODO
504
  'raw_mask':None, #TODO
505
  'image_array':image_array,
506
+ 'mask_array':mask_array,
507
  'metadata':image_overview,
508
  'rad_gradings':patient_grades_dict,
509
  }