open-discussion > nii to dicom conversion
Showing 1-11 of 11 posts
Display:
Results per page:
Nov 25, 2016  07:11 AM | Tayyab Ateeq - UET Taxila
nii to dicom conversion
I have a dataset of brain MRI in nii format. I want to extract all slices in dicom format. I tried xmedcon but it generates blank files. Recommend me some tools to extract all slices from nii file in dcm format. Thanks
Nov 25, 2016  09:11 AM | Allen Waggoner
RE: nii to dicom conversion
Originally posted by Tayyab Ateeq:
I have a dataset of brain MRI in nii format. I want to extract all slices in dicom format. I tried xmedcon but it generates blank files. Recommend me some tools to extract all slices from nii file in dcm format. Thanks

You can do this with Mango.  Just open the NIFTI file (nii) in Mango and then do a save as and select dicom as the format.

Good luck,
Allen
Nov 25, 2016  11:11 AM | Tayyab Ateeq - UET Taxila
RE: nii to dicom conversion
Thanks Allen. I installed Mango and tried to do just like you said but it saved only one slice. I want to save as many slices as possible. Is it possible in Mango?
Thanks
Nov 28, 2016  02:11 AM | Allen Waggoner
RE: nii to dicom conversion
Originally posted by Tayyab Ateeq:
Thanks Allen. I installed Mango and tried to do just like you said but it saved only one slice. I want to save as many slices as possible. Is it possible in Mango?
Thanks

I see, I don't think this is an issue with Mango, I think it is an issue with the structure of your data.  As far as I know, the dicom format only supports spatial dimensions. So if your data has more dimensions, like time, the the data is stored in multiple files.  The nifti header supports up to 7 dimensions, but the first 3 are reserved for spatial dimensions and the fourth is for time.  If you open your nifti file in Mango and select Image Info from the File menu, you will get a popup window.  At the top of this popup window will be two buttons, Summary and Header.  If you click on Header, you will see the full nifti header.  On the line labeled Image Dimensions you might see something like this

Image Dimensions (1-8): 4, 256, 256, 1, 10, 1, 1, 1

The first element is the actual number of dimensions used (4), so this means that each of your images is 256x256, you have one slice and 10 repetitions in time.  If you convert this file to dicom you will get 10 dicom files, each containing one slice.  In the bottom right hand corner of the popup window is a button labeled edit.  If you click on this edit button, a new window will open that will let you edit the elements of the header.  If you change the Image Dimension line to this

Image Dimensions (1-8): 3, 256, 256, 10, 1, 1, 1, 1

when you convert this modified file to dicom, you should get only one file.  In this dicom file the apparent slice dimension will actually be your time dimension.  A bit of a warning though, if you have a large number of time points (now slices), some dicom viewers, might behave strangely.

Allen
Nov 28, 2016  06:11 AM | Tayyab Ateeq - UET Taxila
RE: nii to dicom conversion
Originally posted by Allen Waggoner:
Originally posted by Tayyab Ateeq:
Thanks Allen. I installed Mango and tried to do just like you said but it saved only one slice. I want to save as many slices as possible. Is it possible in Mango?
Thanks

I see, I don't think this is an issue with Mango, I think it is an issue with the structure of your data.  As far as I know, the dicom format only supports spatial dimensions. So if your data has more dimensions, like time, the the data is stored in multiple files.  The nifti header supports up to 7 dimensions, but the first 3 are reserved for spatial dimensions and the fourth is for time.  If you open your nifti file in Mango and select Image Info from the File menu, you will get a popup window.  At the top of this popup window will be two buttons, Summary and Header.  If you click on Header, you will see the full nifti header.  On the line labeled Image Dimensions you might see something like this

Image Dimensions (1-8): 4, 256, 256, 1, 10, 1, 1, 1

The first element is the actual number of dimensions used (4), so this means that each of your images is 256x256, you have one slice and 10 repetitions in time.  If you convert this file to dicom you will get 10 dicom files, each containing one slice.  In the bottom right hand corner of the popup window is a button labeled edit.  If you click on this edit button, a new window will open that will let you edit the elements of the header.  If you change the Image Dimension line to this

Image Dimensions (1-8): 3, 256, 256, 10, 1, 1, 1, 1

when you convert this modified file to dicom, you should get only one file.  In this dicom file the apparent slice dimension will actually be your time dimension.  A bit of a warning though, if you have a large number of time points (now slices), some dicom viewers, might behave strangely.

Allen

I opened file info. There is no label such as Image dimension in header section. In summary there is one. 
Image Dimensions (X, Y, Z): 512 x 512 x 150
Regards
Nov 28, 2016  08:11 AM | Allen Waggoner
RE: nii to dicom conversion
Originally posted by Tayyab Ateeq:
I opened file info. There is no label such as Image dimension in header section. In summary there is one. 
Image Dimensions (X, Y, Z): 512 x 512 x 150
Regards

Is this summary for the nifti file or the dicom file?  The nifti file must have a line for image dimensions.  The dicom header does not have an image dimensions tag.  Whichever file the summary is from, it says there are 150 slices.
Nov 28, 2016  05:11 PM | Tayyab Ateeq - UET Taxila
RE: nii to dicom conversion
Originally posted by Allen Waggoner:
Originally posted by Tayyab Ateeq:
I opened file info. There is no label such as Image dimension in header section. In summary there is one. 
Image Dimensions (X, Y, Z): 512 x 512 x 150
Regards

Is this summary for the nifti file or the dicom file?  The nifti file must have a line for image dimensions.  The dicom header does not have an image dimensions tag.  Whichever file the summary is from, it says there are 150 slices.

This is the summary of NIFTI file and I have found out about image dimensions. It says Image Dimensions (1-8): 3, 512, 512, 150, 1, 1, 1, 1 which means I have 3 dimensions, 150 slices and each image is 512 x 512. I want to to extract all these 150 slices as seperate dicom files. Thanks
Nov 29, 2016  03:11 AM | Allen Waggoner
RE: nii to dicom conversion
Originally posted by Tayyab Ateeq:
Originally posted by Allen Waggoner:
Originally posted by Tayyab Ateeq:
I opened file info. There is no label such as Image dimension in header section. In summary there is one. 
Image Dimensions (X, Y, Z): 512 x 512 x 150
Regards

Is this summary for the nifti file or the dicom file?  The nifti file must have a line for image dimensions.  The dicom header does not have an image dimensions tag.  Whichever file the summary is from, it says there are 150 slices.

This is the summary of NIFTI file and I have found out about image dimensions. It says Image Dimensions (1-8): 3, 512, 512, 150, 1, 1, 1, 1 which means I have 3 dimensions, 150 slices and each image is 512 x 512. I want to to extract all these 150 slices as separate dicom files. Thanks

Okay, I guess I misunderstood, I thought your nifti data was a time-series of a single slice and you wanted to convert it to a single dicom.  But if I understand what you wrote here correctly, it seems it is a 3D data set and you want to generate separate dicom files for each slice.  Is that correct?  Maybe Mango can do this, but I don't see an obvious way.  There is a Mango discussion forum on the Mango website, you might ask for help there.  But if I were going to do this, I would do it in Matlab.  To create dicom files in Matlab, you need the image processing toolbox.  Then you can just read in the nifti file and write the dicom files as you like.
Nov 29, 2016  07:11 AM | Tayyab Ateeq - UET Taxila
RE: nii to dicom conversion
Originally posted by Allen Waggoner:
Originally posted by Tayyab Ateeq:
Originally posted by Allen Waggoner:
Originally posted by Tayyab Ateeq:
I opened file info. There is no label such as Image dimension in header section. In summary there is one. 
Image Dimensions (X, Y, Z): 512 x 512 x 150
Regards

Is this summary for the nifti file or the dicom file?  The nifti file must have a line for image dimensions.  The dicom header does not have an image dimensions tag.  Whichever file the summary is from, it says there are 150 slices.

This is the summary of NIFTI file and I have found out about image dimensions. It says Image Dimensions (1-8): 3, 512, 512, 150, 1, 1, 1, 1 which means I have 3 dimensions, 150 slices and each image is 512 x 512. I want to to extract all these 150 slices as separate dicom files. Thanks

Okay, I guess I misunderstood, I thought your nifti data was a time-series of a single slice and you wanted to convert it to a single dicom.  But if I understand what you wrote here correctly, it seems it is a 3D data set and you want to generate separate dicom files for each slice.  Is that correct?  Maybe Mango can do this, but I don't see an obvious way.  There is a Mango discussion forum on the Mango website, you might ask for help there.  But if I were going to do this, I would do it in Matlab.  To create dicom files in Matlab, you need the image processing toolbox.  Then you can just read in the nifti file and write the dicom files as you like.

Ok. I tried to do it in MATLAB but failed. I don't think that basic support to manipulate NIFTI files is provided in MATLAB thats why I shifted to other tools like xmedcon and ITK-Snap to do it manually. Maybe I am wrong, if you think it is possible in MATLAB then plz recommend me some links. Many Thanks 
Nov 29, 2016  10:11 AM | Allen Waggoner
RE: nii to dicom conversion
Originally posted by Tayyab Ateeq:
Ok. I tried to do it in MATLAB but failed. I don't think that basic support to manipulate NIFTI files is provided in MATLAB thats why I shifted to other tools like xmedcon and ITK-Snap to do it manually. Maybe I am wrong, if you think it is possible in MATLAB then plz recommend me some links. Many Thanks 

Matlab does not have any native routines for reading nifti as far as I know, but many people have written routine for doing this.  In you search for nifti in the Matlab fileexchange, you will get many hits.  This one seems popular

http://www.mathworks.com/matlabcentral/fileexchange/8797-tools-for-nifti-and-analyze-image


Also Freesurfer (http://freesurfer.net/) comes with a matlab library, which among many other things, includes routines for both reading and writing nifti files.

Nifti is the file format that SPM (http://www.fil.ion.ucl.ac.uk/spm/) uses, so there are routines within SPM that can read nifti files.

mrTools (http://gru.stanford.edu/doku.php/mrtools...) also used the nifti format and therefore includes tools for reading nifti files. 


I am sure the must be many other routines available as well. For that matter, it should not take too many lines of code to write a simple nifti reader.


mrTools requires Optimization, Statistics and Image Processing toolboxes. SPM does not require any toolboxes.  I am not sure about the other options I listed.



To creating the dicom files in Matlab, you need the image processing toolbox

Good Luck
Dec 6, 2016  05:12 AM | Tayyab Ateeq - UET Taxila
RE: nii to dicom conversion
Originally posted by Allen Waggoner:
Originally posted by Tayyab Ateeq:
Ok. I tried to do it in MATLAB but failed. I don't think that basic support to manipulate NIFTI files is provided in MATLAB thats why I shifted to other tools like xmedcon and ITK-Snap to do it manually. Maybe I am wrong, if you think it is possible in MATLAB then plz recommend me some links. Many Thanks 

Matlab does not have any native routines for reading nifti as far as I know, but many people have written routine for doing this.  In you search for nifti in the Matlab fileexchange, you will get many hits.  This one seems popular

http://www.mathworks.com/matlabcentral/fileexchange/8797-tools-for-nifti-and-analyze-image


Also Freesurfer (http://freesurfer.net/) comes with a matlab library, which among many other things, includes routines for both reading and writing nifti files.

Nifti is the file format that SPM (http://www.fil.ion.ucl.ac.uk/spm/) uses, so there are routines within SPM that can read nifti files.

mrTools (http://gru.stanford.edu/doku.php/mrtools...) also used the nifti format and therefore includes tools for reading nifti files. 


I am sure the must be many other routines available as well. For that matter, it should not take too many lines of code to write a simple nifti reader.


mrTools requires Optimization, Statistics and Image Processing toolboxes. SPM does not require any toolboxes.  I am not sure about the other options I listed.



To creating the dicom files in Matlab, you need the image processing toolbox

Good Luck

Ok. I have done it using following script
http://www.neuro.mcw.edu/~chumphri/matlab/readnifti.m

Thank you so much for your help Allen.