How to Convert a Dicom Series into one Nifti File (Python)

In this article, I will give you a quick way of how to convert a directory of Dicom files into one volume file (nifti).

Mohammed El Amine Mokhtari
2 min readMay 16, 2021

The original article on my blog website here.

Image by MART PRODUCTION from Pexels

Introduction

In medical imaging, we use often two types of images, Dicom or Nifti which are the famous ones. But there is a difference between these two types of images or we can say files because they have more information than a normal image. If you want to know these differences then you can see this article.

Now if we want to create a nifti file, means that we will take a set of slices then put them together with the extension “.nii ”.

The process

To do this work you need only two lines of code using python with a library called “dicom2nifti”.

So before starting the code, we need to install the library using the pip installer.

pip install dicom2nifti

After installing the library, we will write the two lines that I told you about, the first one is to import the library and the second one is to use a function that will do all the work.

That’s it, by using these two lines you will get your one volume file.

Note: for the path_to_save_nifti_file you should know that you need to include the file name with the extension “.nii ” and if you want a compressed file then you can add “.gz ”…

Read more

Link here

You Want to Learn Deep Learning for Medical Imaging!

Coming soon is a comprehensive medical imaging course covering 2D and 3D segmentation using Monai and PyTorch with added support. Join the waiting list to receive notifications of any course updates.

Subscribe to my newsletter to get all the updates about my work :).

--

--

Mohammed El Amine Mokhtari
Mohammed El Amine Mokhtari

Written by Mohammed El Amine Mokhtari

I'm a computer vision research assistant, YouTuber and online content creator. Co-founder at: https://pycad.co/

No responses yet