Reads DCM volume with grid transform with python

Hi all,

I want to read a DCM file and output it with the transform contained in the file.

But now that I’m using SimpleITK, it only outputs untransformed DCM files.

Can you suggest a method?

My code:

def readDCM(folder_path, win_level=50, win_width=100):
  series_reader = sitk.ImageSeriesReader()
  series_IDs = series_reader.GetGDCMSeriesIDs(folder_path)
  if not series_IDs:
      raise Exception("No DICOMs were found in the directory. Please select a different directory.")
      
  series_file_names = series_reader.GetGDCMSeriesFileNames(folder_path, series_IDs[0])
  series_reader.SetFileNames(series_file_names)
  image = series_reader.Execute()

  image_array = sitk.GetArrayFromImage(image)
  image_array = np.clip(image_array, win_level - 0.5 - (win_width - 1) / 2, win_level - 0.5 + (win_width - 1) / 2)
  image_array = (image_array - (win_level - 0.5)) / (win_width - 1)

  return image_array

Best,
Thirawat

SimpleITK’s DICOM reader can only read the most basic images.

dcm2niix tool can deal with a bit more complicated cases. It is a standalone toolfor converting DICOM to NRRD or NIFTI.

For advanced slice grouping, tilted-gantry image rectification, variable slice spacing compensation, etc. you need Slicer’s DICOM reader infrastructure. See examples how to use it here.

I’ve tried to read the docs, but I’m not sure if there is a way to make it possible to use the slicer in colab.

I tried to read docs but not sure if it can be used in colab.

Or is there another python library to recommend?

Let me explain more. In my dicom file there is

  • dicom volume
  • grid transform

or I can save transform on dicom volume?

I solve my problem in another way [click].

btw thank you, everyone.