Commit 8fa8e038459bb9a8771daa13525e1a2e14ab800c

Authored by tfmoraes
1 parent c171a2bd

ENH: Returning scalar range on creating memmap from dicom

Showing 1 changed file with 13 additions and 1 deletions   Show diff stats
invesalius/data/imagedata_utils.py
... ... @@ -476,10 +476,20 @@ def dcm2memmap(files, slice_size, orientation):
476 476 matrix = numpy.memmap(temp_file, mode='w+', dtype='int16', shape=shape)
477 477 dcm_reader = vtkgdcm.vtkGDCMImageReader()
478 478 cont = 0
  479 + max_scalar = None
  480 + min_scalar = None
479 481 for n, f in enumerate(files):
480 482 dcm_reader.SetFileName(f)
481 483 dcm_reader.Update()
482 484 image = dcm_reader.GetOutput()
  485 +
  486 + min_aux, max_aux = image.GetScalarRange()
  487 + if min_scalar is None or min_aux < min_scalar:
  488 + min_scalar = min_aux
  489 +
  490 + if max_scalar is None or max_aux > max_scalar:
  491 + max_scalar = max_aux
  492 +
483 493 array = numpy_support.vtk_to_numpy(image.GetPointData().GetScalars())
484 494 if orientation == 'CORONAL':
485 495 array.shape = matrix.shape[0], matrix.shape[2]
... ... @@ -494,7 +504,9 @@ def dcm2memmap(files, slice_size, orientation):
494 504 cont += 1
495 505  
496 506 matrix.flush()
497   - return matrix, temp_file
  507 + scalar_range = min_scalar, max_scalar
  508 +
  509 + return matrix, scalar_range, temp_file
498 510  
499 511 def to_vtk(n_array, spacing, slice_number, orientation):
500 512 try:
... ...