What Is The Difference Between Dicom And Nifti Images?
In this article, we will talk a little bit about the Nifti files and the difference between them and normal 2D slices (Dicom). Then we will see how to visualize and convert them.
The original article on my blog website here.
Before talking about the differences between these two types of images, we should know first what these types are.
So the answer is that they are both images or we call say files special for medical analysis. Because in general, 80% of people use normal images like JPEG, PNG, Tiff … but in the medical field, these images are not helpful because for more precise analysis we need more information about the patient and about how the image was taken.
This information is stored in the same file either Dicom or Nifti and to call them we can use something called tags, so we use these tags to return the information that we want like the patient ID, name… Those were the information only for the patient but there is the other side that is special for the image itself. We call them also by using the tags but they are a little bit different, from this information there is a component called pixel_data array which is an array that contains the values of the pixels that we can visualize, the dimensions of the pixel (in case you want to calculate an area from the body, for example, tumor), the depth of the pixel…
This definition was in general because you can say that if the two types (Dicom and Nifti) have the same functionalities so what is the use?
Don’t worry about that, I had this problem too at first and the articles that I found were not straight to the point so I was lost, but doing some analysis using the 3D slicer I could understand the difference between them and you will see that it is very easy to understand.
The Dicom image (or file) is a 2D image even though it has a volume but in reality, it is a 2D image because it has only one slice of an MRI, CT, TEP…
Instead of that, the Nifti file can contain a set of these Dicom images. To give you a quick example that I am sure you will understand, a video is a set of frames so when we put all the frames together with a delay between each frame then we get the video, so the same this here we can say that the Dicom images are frames and when we put them together we get the Nifti.
So a Nifti image is a whole representation of a part of the human body, that contains all the slices that we took using the X-rays or any other method.
In this case, the volume or the depth of the Dicom slices will be the distance between each two Dicom images. So now we have one Nifti file that represents all the slices with all the other information that we talked about in the Dicom part.
How to visualize the Nifti images?
In this article, we talked about how to visualize or convert a Dicom image using python and now I will show you how to visualize a Nifti file using multiple ways.
If you don’t care about programming so there is an easy way of how to visualize them using some free software, for that you can use:
- 3D slicer
- ITK snap
- And there is more software that does almost the same thing.
If you use the 3D slicer for example you can do a lot of stuff with the Nifti images, you can visualize them, convert them into Dicom slices, JPG, or PNG images …
How to visualize a Nifti image using the 3D slicer
It is very easy actually. First, you can download the software from this link and install it, then you open it normally.
You will get this window:
Then you can choose either click on DATA in the top bar or you can directly drag and drop the Nifti file in this window and it will be open. You will visualize the file in the three cuts (axial, coronal, and sagittal), here is an example:
And when you scroll you will go to the next or the previous slice and in this case, you can analyze the images with more precision.
How to convert a Nifti file into DICOM slices
To do this it is also easy using the 3D slicer, you need to click on the search button on top of the window then you type ‘create Dicom series, after that, you will get this window:
Now, on your left, you see that there are some parameters that you can play with, but the basic thing is to choose the input file and the output directory then click apply and you will get your DICOM slices.
How to convert a set of DICOM files into one Nifti file
Now if you want to do the backward which means you go from multiple Dicom slices and create one Nifti file, in this case, all what you need to do is to choose the directory of your DICOM images by clicking on the button DATA then wait until it opens all the slices, then click on the button save on top, you will get this window:
so here you can choose the name and the file extension (in this case it is ‘.nii’ for the Nifti) then you can change the directory and click save.
How to visualize a Nifti image using Matlab
Now after that you saw how to manipulate these files using a software, you may need to know how to manipulate them using some programming language, for that, I will show you how to do that using Matlab and it is the easiest one.
As we saw in this article how to visualize a DICOM image using Python, we used the tag ‘pixel array’ that returns the values of the pixels, now we have the same idea but instead of having only one-pixel array, we will have an array of pixel arrays and each item of this array contains one image that we can visualize or convert into normal image…
So to do that in Matlab you need only the following lines of code:
nifti = niftiread(folderName);figure, imshow((nifti_res(:, :, slice)), );
So you should replace the word ‘slice’ by the number of the slice that you want to display.