pythonpydicomsimpleitkmri

loading dicoms with pydicom and sitk results different outputs


My problem is a bit wired. I am working on Prostate MRI dataset which contains dicom images. When I load dicom files using Simple ITK the output numpy array's dtype will be float64 . But when I load same dicom files using pydicom , the output numpy array's dtype will be uint16 And the problem isn't just this. Pixel intensities would be different when using different module. So my question is why they look different and which one is correct and why these modules load data differently? this is the code I'm using to load dcm files.

import pydicom
import SimpleITK as sitk

path = 'dicoms/1.dcm'


def read_using_sitk():
    reader = sitk.ImageFileReader()
    reader.SetFileName(path)
    image = reader.Execute()
    numpy_array = sitk.GetArrayFromImage(image)
    return numpy_array.dtype


def read_using_pydicom():
    dataset = pydicom.dcmread(path)
    numpy_array = dataset.pixel_array
    return numpy_array.dtype

Solution

  • The difference is that pydicom loads the original data as saved in the dataset (which is usually uint16 for MR data), while SimpleITK does some preprocessing (most likely applying the LUT) and returns the processed data as a float array.

    In pydicom, to get data suitable for display, you have to apply some lookup table yourself, usually the one coming with the image.

    If you have a modality LUT (not very common for MR data), you first have to apply that using apply_modality_lut, while for the VOI LUT you use apply_voi_lut. This will apply both modality and VOI LUT as found in the dataset:

    ds = dcmread(fname)
    arr = ds.pixel_array
    out = apply_modality_lut(arr, ds)
    display_data = apply_voi_lut(out, ds, index=0)
    

    This can be savely used even if no modality or VOI LUT is present in the dataset - in this case just the input data is returned.
    Note that there can be more than one VOI LUT in a DICOM image, for example to show different kinds of tissue - thus the index argument, though that is also not very common in MR images.