# How to convert dicom files to nrrd

**URL:** <https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540>\
**Category:** Support\
**Created:** [June 20, 2017, 1:48pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540 "2017-06-20T13:48:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josiah\_McAllister](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@Josiah\_McAllister](https://discourse.slicer.org/u/Josiah_McAllister)\
**Post date:** [June 20, 2017, 1:48pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/1 "2017-06-20T13:48:33Z")

</div>

Operating system:Windows  
Slicer version:4.6.2  
Expected behavior:  
Actual behavior:

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [June 20, 2017, 1:49pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/2 "2017-06-20T13:49:33Z")

</div>

Use the DICOM module to import the files, and then export as NRRD:

[https://www.slicer.org/wiki/Documentation/Nightly/Modules/DICOM](https://www.slicer.org/wiki/Documentation/Nightly/Modules/DICOM)

---

<div class="post-metadata">

**Author:** ![Josiah\_McAllister](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@Josiah\_McAllister](https://discourse.slicer.org/u/Josiah_McAllister)\
**Post date:** [June 20, 2017, 2:01pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/3 "2017-06-20T14:01:54Z")

</div>

When I do that, only one of the three files saves as an nrrd. I need the  
segmentation to also be in nrrd form in order for it to be used by  
pyradiomics. How can I convert that segment then also to nrrd, as it is not  
a choice to save it as that.

---

<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:** [June 20, 2017, 2:10pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/4 "2017-06-20T14:10:30Z")

</div>

Export it to labelmap node using Segmentations module (Import/Export section).

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 21, 2017, 5:12pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/5 "2017-06-21T17:12:39Z")

</div>

> [@Josiah\_McAllister](#):
>
> I need the  
> segmentation to also be in nrrd form in order for it to be used by  
> pyradiomics

If you are on Mac or Windows, you can also use SlicerRadiomics extension to calculate pyradiomics features. SlicerRadiomics works with either label maps, or segmentations.

> **[GitHub - AIM-Harvard/SlicerRadiomics: A Slicer extension to provide a GUI...](https://github.com/AIM-Harvard/SlicerRadiomics)**
>
> A Slicer extension to provide a GUI around pyradiomics - GitHub - AIM-Harvard/SlicerRadiomics: A Slicer extension to provide a GUI around pyradiomics

---

<div class="post-metadata">

**Author:** ![Josiah\_McAllister](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@Josiah\_McAllister](https://discourse.slicer.org/u/Josiah_McAllister)\
**Post date:** [June 21, 2017, 5:31pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/6 "2017-06-21T17:31:34Z")

</div>

Do you know of anywhere I can go to learn how to use SlicerRadiomics? I now  
have it installed, but I cannot find how to use the extension.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 21, 2017, 6:07pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/7 "2017-06-21T18:07:20Z")

</div>

We have very basic usage instructions here: [https://github.com/Radiomics/SlicerRadiomics/blob/master/USAGE.md#usage](https://github.com/Radiomics/SlicerRadiomics/blob/master/USAGE.md#usage)

Are there specific issues where you are confused? It would be helpful to get some feedback what are exactly the challenges using the module.

---

<div class="post-metadata">

**Author:** ![jfhartzell](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jfhartzell](https://discourse.slicer.org/u/jfhartzell)\
**Post date:** [July 21, 2017, 3:18pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/8 "2017-07-21T15:18:09Z")

</div>

Hello, I’m new to Slicer  
Could you send updated instructions for how to convert a DICOM folder to NRRD?  
Thanks  
James

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [July 21, 2017, 5:35pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/9 "2017-07-21T17:35:51Z")

</div>

Please refer to the [comment](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/2) of @ihnorton

You can save the loaded DICOM volume as NRRD in the Save data dialog.

---

<div class="post-metadata">

**Author:** ![b\_s\_umesh\_sherkhane](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/b_s_umesh_sherkhane/32/65688_2.png) [@b\_s\_umesh\_sherkhane](https://discourse.slicer.org/u/b_s_umesh_sherkhane)\
**Post date:** [March 7, 2018, 5:17am UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/10 "2018-03-07T05:17:14Z")

</div>

hello,i am on the same boat,i am looking at mass conversion of thousands of dicom files to nrrd.  
hence thought to use it in python script to automate it. is there any way that i can use command line slicer to mass convert dicom to nrrd ?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [March 7, 2018, 2:39pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/11 "2018-03-07T14:39:27Z")

</div>

You can load DICOM from python like this

```
from DICOMLib import DICOMUtils
DICOMUtils.openDatabase('path/to/tempDatabase') # For batch processing it's better to use a temporary database
DICOMUtils.loadPatientByUID(patientUID)

```

You can load patients by name, UID, and patient ID (an incremental integer Slicer assigns to imported patients), see [https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMUtils.py#L105-L110](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMUtils.py#L105-L110)

Then you can save NRRD like this

```
slicer.util.saveNode(node, 'fileName.nrrd')

```

For this you’ll need the MRML node which you can get in several ways, depending how you want your batch script to operate (for example dynamically with onNodeAdded, by getting the last volume node from the scene, or simply by closing scene after each save and get the only volume node)

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [March 7, 2018, 9:59pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/12 "2018-03-07T21:59:25Z")

</div>

You can also consider one of the many tools out there that are much easier to use than Slicer for batch volume reconstruction (faster, easier to use, possibly more robust).

You can find a list of some of the most popular ones (incomplete, I am sure) here: [https://na-mic.github.io/ProjectWeek/PW27\_2018\_Boston/Projects/DICOMVolumeReconstruction/](https://na-mic.github.io/ProjectWeek/PW27_2018_Boston/Projects/DICOMVolumeReconstruction/).

A number of them (including Slicer converters) are set up in this dockerfile: [https://github.com/QIICR/dcmheat/blob/master/docker/Dockerfile](https://github.com/QIICR/dcmheat/blob/master/docker/Dockerfile) (just noticed [the corresponding container on Docker Hub](https://hub.docker.com/r/qiicr/dcmheat/) is broken, I need to fix that).

How they compare to each other and which specific one to recommend remains the open question (for me at least). As we make progress with the project referenced above, hopefully we will be able to recommend one specific tool, or say that all/subset of them are equivalent for practical purposes.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 7, 2018, 10:23pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/13 "2018-03-07T22:23:27Z")

</div>

And just to make sure this is clear: converting DICOM to nrrd is not a simple well defined operation in general. DICOM is a very expressive and flexible standard and there are several possibilities for any one collection of DICOM files:

- it may correspond to many nrrd files (e.g. different series in a study)
- there may be more than one valid conversion and only the user knows which is preferred
- it may not be possible for nrrd to represent the DICOM data (such as a DICOM structured report or something)

That said, if you are dealing with a fairly standard case like converting one CT series to a nrrd scalar volume there are many good options as @fedorov points out. It all depends on the data and what you hope to use it for. Luckily there are lots of examples to learn from and by writing a script you can control the process to get what you need.

---

<div class="post-metadata">

**Author:** ![S\_Arbabi](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@S\_Arbabi](https://discourse.slicer.org/u/S_Arbabi)\
**Post date:** [March 28, 2024, 10:43am UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/14 "2024-03-28T10:43:31Z")

</div>

I created a nifti dataset (converting dicom to nifti using slicer), and trained an nnUNet segmentation model (with noMirroring trainer).  
in the inference time I use dicom2nifti for nifti generation from new dicom files, then I observe that the segmentation model does not work properly, providing bad segmentations.

I checked volume information of dicom:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/f/5fc35d4cb208ff9e7ee89b797bf75c12a53bc90f.png)

volume information of dicom2nifti generated file:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/8/883af3d5de873b6abd8dbfe4cde82fd33b665bed.png)

and the volume information for a nifti volume I generate in slicer from the same dicom:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/d/2d5b0984ea787805433feb9be32a90aa71c43c9f.png)

any ideas what is a workaround?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 28, 2024, 12:18pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/15 "2024-03-28T12:18:08Z")

</div>

It looks like dicom2nifti (whichever one that is - I believe there are many tools with similar names) interprets the dicom differently than Slicer does. Note that the IJK to RAS matrices differ as do the origins. Probably these are the same geometry in terms of pixels ending up at the same places in space, but the layout of pixels in memory may be different (e.g. slices may be reversed) and it’s possible that the machine learning code doesn’t take this into account.

---

<div class="post-metadata">

**Author:** ![S\_Arbabi](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@S\_Arbabi](https://discourse.slicer.org/u/S_Arbabi)\
**Post date:** [March 28, 2024, 1:34pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/16 "2024-03-28T13:34:06Z")

</div>

I believe the same is the case. What do you suggest to solve this? I can not run slicer on target machine so I have to convert to nifti using another package.

---

<div class="post-metadata">

**Author:** ![dave3d](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dave3d/32/5003_2.png) [@dave3d](https://discourse.slicer.org/u/dave3d)\
**Post date:** [March 28, 2024, 1:52pm UTC](https://discourse.slicer.org/t/how-to-convert-dicom-files-to-nrrd/540/17 "2024-03-28T13:52:43Z")

</div>

I wrote a python script using SimpleITK that scans a directory for DICOM series and can convert any series it finds to NRRD (or Nifti).

Here’s a link to it on Github:

> <https://github.com/dave3d/sitk_tools/blob/main/dicomseries.py>
