# Reads DCM volume with grid transform with python

**URL:** https://discourse.slicer.org/t/reads-dcm-volume-with-grid-transform-with-python/28998
**Category:** Support
**Tags:** segmentation, dicom, python
**Created:** [April 18, 2023, 11:26pm UTC](https://discourse.slicer.org/t/reads-dcm-volume-with-grid-transform-with-python/28998 "2023-04-18T23:26:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Thirawat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thirawat/32/65667_2.png) [@Thirawat](https://discourse.slicer.org/u/Thirawat)
#### Post date: [April 18, 2023, 11:26pm UTC](https://discourse.slicer.org/t/reads-dcm-volume-with-grid-transform-with-python/28998/1 "2023-04-18T23:26:47Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [April 18, 2023, 11:32pm UTC](https://discourse.slicer.org/t/reads-dcm-volume-with-grid-transform-with-python/28998/2 "2023-04-18T23:32:49Z")

</div>

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](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#dicom).

---

<div class="post-metadata">

### Author: ![Thirawat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thirawat/32/65667_2.png) [@Thirawat](https://discourse.slicer.org/u/Thirawat)
#### Post date: [April 19, 2023, 8:40am UTC](https://discourse.slicer.org/t/reads-dcm-volume-with-grid-transform-with-python/28998/3 "2023-04-19T08:40:34Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Thirawat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thirawat/32/65667_2.png) [@Thirawat](https://discourse.slicer.org/u/Thirawat)
#### Post date: [April 19, 2023, 9:17am UTC](https://discourse.slicer.org/t/reads-dcm-volume-with-grid-transform-with-python/28998/4 "2023-04-19T09:17:30Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Thirawat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thirawat/32/65667_2.png) [@Thirawat](https://discourse.slicer.org/u/Thirawat)
#### Post date: [April 28, 2023, 4:33am UTC](https://discourse.slicer.org/t/reads-dcm-volume-with-grid-transform-with-python/28998/5 "2023-04-28T04:33:40Z")

</div>

I solve my problem in another way [[click]](https://discourse.slicer.org/t/transforme-segmentaion/29150/5).

btw thank you, everyone.
