Commit e53432ed26858d8a2687631986a283bf433d8449
1 parent
1d943e8d
Exists in
master
and in
67 other branches
ENH: Using vtkgdcmImageReader instead gdcm.ImageReader.
Because it was necessary to do some extra works, like some math to calculate the hounsfield units, now we are using vtkgdcmImageReader instead of gdcm.ImageReader.
Showing
1 changed file
with
7 additions
and
30 deletions
Show diff stats
invesalius/data/imagedata_utils.py
| ... | ... | @@ -456,25 +456,6 @@ class ImageCreator: |
| 456 | 456 | |
| 457 | 457 | return imagedata |
| 458 | 458 | |
| 459 | -def get_gdcm_to_numpy_typemap(): | |
| 460 | - """Returns the GDCM Pixel Format to numpy array type mapping.""" | |
| 461 | - _gdcm_np = {gdcm.PixelFormat.UINT8 :numpy.int8, | |
| 462 | - gdcm.PixelFormat.INT8 :numpy.uint8, | |
| 463 | - #gdcm.PixelFormat.UINT12 :numpy.uint12, | |
| 464 | - #gdcm.PixelFormat.INT12 :numpy.int12, | |
| 465 | - gdcm.PixelFormat.UINT16 :numpy.uint16, | |
| 466 | - gdcm.PixelFormat.INT16 :numpy.int16, | |
| 467 | - gdcm.PixelFormat.UINT32 :numpy.uint32, | |
| 468 | - gdcm.PixelFormat.INT32 :numpy.int32, | |
| 469 | - #gdcm.PixelFormat.FLOAT16:numpy.float16, | |
| 470 | - gdcm.PixelFormat.FLOAT32:numpy.float32, | |
| 471 | - gdcm.PixelFormat.FLOAT64:numpy.float64 } | |
| 472 | - return _gdcm_np | |
| 473 | - | |
| 474 | -def get_numpy_array_type(gdcm_pixel_format): | |
| 475 | - """Returns a numpy array typecode given a GDCM Pixel Format.""" | |
| 476 | - return get_gdcm_to_numpy_typemap()[gdcm_pixel_format] | |
| 477 | - | |
| 478 | 459 | def dcm2memmap(files, slice_size): |
| 479 | 460 | """ |
| 480 | 461 | From a list of dicom files it creates memmap file in the temp folder and |
| ... | ... | @@ -483,20 +464,16 @@ def dcm2memmap(files, slice_size): |
| 483 | 464 | temp_file = tempfile.mktemp() |
| 484 | 465 | shape = len(files), slice_size[0], slice_size[1] |
| 485 | 466 | |
| 486 | - matrix = numpy.memmap(temp_file, mode='w+', dtype='uint16', shape=shape) | |
| 467 | + matrix = numpy.memmap(temp_file, mode='w+', dtype='int16', shape=shape) | |
| 487 | 468 | |
| 488 | 469 | for n, f in enumerate(files): |
| 489 | - dcm_image = gdcm.ImageReader() | |
| 490 | - dcm_image.SetFileName(f) | |
| 491 | - dcm_image.Read() | |
| 492 | - | |
| 493 | - image = dcm_image.GetImage() | |
| 494 | - pf = image.GetPixelFormat().GetScalarType() | |
| 495 | - dtype = get_numpy_array_type(pf) | |
| 470 | + dcm_reader = vtkgdcm.vtkGDCMImageReader() | |
| 471 | + dcm_reader.SetFileName(f) | |
| 472 | + dcm_reader.Update() | |
| 496 | 473 | |
| 497 | - dcm_array = image.GetBuffer() | |
| 498 | - array = numpy.frombuffer(dcm_array, dtype) | |
| 499 | - array.shape = slice_size | |
| 474 | + image = dcm_reader.GetOutput() | |
| 475 | + array = numpy_support.vtk_to_numpy(image.GetPointData().GetScalars()) | |
| 476 | + array.shape = matrix.shape[1], matrix.shape[2] | |
| 500 | 477 | matrix[n] = array |
| 501 | 478 | |
| 502 | 479 | matrix.flush() | ... | ... |