NIfTI conversion, visualization and transformation tools
Updated 22 Feb 2023

Editor's Note: This file was selected as MATLAB Central Pick of the Week

DICOM to NIfTI conversion, DICOM and NIfTI tools, NIfTI visualization (version 2024.06.06)

View xiangruili/dicm2nii on File Exchange Open in MATLAB Online


Convert DICOM into NIfTI. It can also convert PAR/XML/REC, HEAD/BRIK, MGZ and BrainVoyager files into NIfTI.


Create, load, save NIfTI file. Support both version 1 and 2 NIfTI, and variety of data type.


Visualize NIfTI. Can also visualize any file convertible to NIfTI by dicm2nii.


Affine registration of images with the same modality.


Removes face and neck structure from T1w/T2w NIfTI.


Perform motion correction on a NIfTI.


Perform slice timing correction on a NIfTI.


Transform a NIfTI into different resolution, or into a template space.

dicm_hdr, dicm_img, dicm_dict, dicm_save, dicm_val_rep

Read/write DICOM header and image, independent of Matlab Image Processing Toolbox.

rename_dicm, sort_dicm, anonymize_dicm

DICOM tools performing the tasks as indicated by the name.


Real time motion/image monitor and more for Siemens scanner.

Cite As

Xiangrui Li (2024). xiangruili/dicm2nii (https://github.com/xiangruili/dicm2nii/releases/tag/v2023.02.23), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes

See release notes for this release on GitHub: https://github.com/xiangruili/dicm2nii/releases/tag/v2023.02.23


update version


1. use GetFullPath from Jan
2. accept mixture of files and folders as input
3. other fixes


dicm2nii: implement 16-bit range scale (default off);
dicm_hdr: bug fix for insufficient bytes for search method; improvement for philips_par&xml
Switch to Github


1. dicm_hdr: can read Philips xml file; many improvements for PAR dealing
2. dicm2nii: can deal with incomplete volume for Philips PAR/XML/DICOM;
better dealing for different complex image types.


dicm2nii: take care of some special Philips cases:
1. store VolumeTiming from FrameReferenceTime, seen in pet data;
2. bug fix to remove Philips DTI ADC vol;
3. switch to floating value for rescale.


1. dicm2nii: bug fix for long file name
2. some minor fix.


1. check NIfTI struct in workspace when adding overlay
2. Implement 'Standard deviation' like for 'time course'.
dicm_hdr->philips_par: bug fix for wrong slice flip; work for incomplete volume


1. nii_viewer: map inflated surface click to correct location in volume, even for old matlab
2. dicm2nii: bug fix for fieldmap TEs
3. other minor fixes and improvement.


nii_viewer: support inflated surface to volume mapping. Tested only for HCP surfaces.


surface view uses combined overlay, so it works smoothly for different environment.


1. nii_viewer: implement surface view for CIfTI (HCP gii template included).
2. dicm_hdr: bug fix for possible slice flip in Philips PAR. Thx ShereifH.


1. dicm2ii: work for Siemens multiframe dicom.
2. nii_viewer: try to convert back to volume to visualize CIfTI.
3. dicm_img: bug fix for compressed dicom without offset table.


1. nii_view: two more layout including compact one-row display
2. other minor improvement and fix


1. Save VolumeTiming for missing volumes based on BIDS;
2. Correct Siemens readout time;
3. Use GE SLICEORDER if RTIA_timer not available;
4. Always store TE and readout for distortion correction.


1. Bug fix for reading Philips PAR file;
2. Better tab auto-completion.


1. Add functionSignatures.json file for tab auto-completion;
2. Allow regularly missing InstanceNumbers, like dicom from CMRR for auditory study;
3. Try to take care of GitHub download, so prepare for GitHub hosting.


1. dicm2nii & nii_viewer: can read big-endian AFNI image;
2. dicm2nii: set multiband slice_code to 0 to avoid FreeSurfer error;
3. Users need to manually download once to fix package update from GUI;
4. nii_viewer: improved Ctrl-drop to add overlay


1. dicm2nii: better precision requirement for ImagePositionPatient;
2. dicm2nii: bug fix for mixed MAG/PHASE multi-frame dicom with >2 volumes.


1. nii_viewer: Can open DICOM etc files by converting into NIfTI without saving, allowing to view image from one or more files without converting.
2. dicm2nii: can convert FreeSurfer mgh/mgz files into NIfTI.
3. other fixes and improvement.


anonymize_dicm: replace PatientName with ID rather than scratching it.


1. nii_moco: new implementation to perform motion correction;
2. anonymize_dicm: new implementation to remove Patient Name in dicom files;
3. dicm2nii: transform CT image with gantry tilt;
4. other minor improvement and fix.


1. dicm2nii: fix for irregular image order in Philips multi-frame dicom;
2. dicm_hdr: avoid error due to missing value for a tag;
3. other minor improvements.


1. nii_viewer: allow to manually remove excessive neck tissue;
2. nii_viewer: better overlay treatment for Analyze files;
3. nii_tool: fast hdr/ext read for gz file by memory gunzip;
4. minor improvement here and there.


1. nii_viewer: implement warped overlay;
2. nii_viewer: implement “Save volume as”;
3. dicm_hdr: fix problem for some Philips PAR file;
4. Other minor fixes.


dicm2nii: fix bug introduced by update hours ago (slope/intercept wrongly applied to files expect 1st).


1. dicm2nii: Add preferences to GUI
2. dicm2nii: Convert series with inconsistent Rescale slope or intercept
3. other minor fixes and improvement


1. dicm2nii: add pref to allow to not use SeriesInstanceUID;
2. nii_viewer: option to load single volume for large dataset;
3. dicm_hdr: can read dicom without PixelData;
4. other minor fixes and improvement.


nii_viewer: file list GUI improvement; implement histogram plot and sphere ROI creation.
Other minor fix and improvement.


nii_viewer: add 'RGB' LUT so 3-volume image can be in RGB;
dicm2nii: avoid skipping series due to empty-PixedlData junk dicom;
allow setpref to not save PatientName and not use parfor;
Other minor fixes.


dicm2nii: always save ReadoutSeconds for topup;
nii_viewer: implement image center of gravity display;
Other minor fixes and improvements.


nii_stc: new file for nifti slice timing correction.
dicm_img: try to support files with BitsStored~=HighBit+1.
dicm2nii & nii_viewer: minor fixes.


dicm2nii: big fix for error due to missing file(s).


1. GE bvec sign correction for sag/cor acquisition;
2. Avoid error due to missing info in Siemens B15 CSASeriesHeaderInfo.
Bug fix for zoom in/out by key press.


nii_viewer: Update phase LUTs to three; Add "Open in new window"


Corrected version number


dicm2nii: better mosaic detection for old/bad data; Convert MoCo series by default.
nii_viewer: added two LUT for complex data: useful for retinotopy.
dicm_hdr: performance tweaks: almost 100% improvement.
Many minor fixes and improvements.


1. dicm2nii: Fix Siemens mosaic detection for rare cases.
2. nii_viewer: Allow background image to move in stack;
Remove some restriction for DTI vector lines.
3. Some minor fixes.


1. nii_viewer: bug fix for messed-up callback in set_file;
2. some minor improvement.


1. dicm2nii: support big endian dicom files;
2. other minor fixes.


check update: fix the problem to download into current directory.


1. nii_viewer: implement time course plot;
2. nii_viewer: fix hanging problem for some Matlab versions due to invisible figure;
3. dicm_img: bug fix for not casting bytes into double.


1. Implement update check from dicm2nii and nii_viewer GUI;
2. Use matlab pref method for dicm2nii, nii_tool and nii_viewer;
3. dicm2nii: fix for files missing SeriesInstanceUID;
4. nii_viewer: some improvement and bug fix. Faster display


Fixes and improvements for dicm2nii, nii_tool, and mostly for nii_viewer:
1. Friendly file list GUI;
2. add overlay by Ctrl drag&drop;
3. modulated image display;
4. ROI label display, such as AAL;
5. more LUT options, including custom LUT.


nii_viewer: bug fix introduced in previous update (reorient problem)


1. avoid error for white background under Linux;
2. bug fix for alpha and case of unmatched s/qform.


nii_viewer fix and improvement:
1. bug fix for nii with sform=0;
2. Add "Show NIfTI essentials";
3. better effect for white backgroun.


1. dicm2nii: GUI supports drag and drop of folder/files; optionally save JSON file;
2. nii_tool: partial gz unzip makes hdr only read much faster;
3. nii_viewer: Key navigation and zoom implemented; allow L/R flip, white background and more.


Bug fix for Show NIfTI hdr/ext


1. Implement nii_viewer.m for nii visualization;
2. Add file nii_xform to resample/transform nii image;
3. Some minor improvement for dicm2nii, nii_tool etc;
4. Include dndcontrol by Maarten van der Seijs.


1. Take care irregular slice ordering for PAR/REC and multiframe dicom;
2. Bug fix for case of nSlices = 1;
3. Other minor fixes.

1. nii_tool: auto detects RGB style for image reading;
2. try to fix slice timing for some multiband data;
3. some other minor fixes.

Major: Store text NIfTI extension for information, like DTI bval/bvec, slice timing, unwarp parameters etc
Minor: more missing files check and some minor fixes and improvements

Do not store ecode=40 NIfTI extension due to possible problem with FSL

Fix problems with latest Matlab versions: uint32 figure handle and parpool.

1. Can convert BrainVoyager files into NIfTI;
2. Bug fix for phaseDir for Philips data;
3. nii_tool allows to set default NIfTI version and RGB style;
4. Other minor fix and improvement.

1. Works multi subject/study data;
2. Won't skip derived data, such as those from GLM/DTI;
3. Transformation takes care of possible shear at slice direction;
4. Many minor improvement.

1. Bug fix for phase encoding direction;
2. Improved DTI bvec sign treatment;
3. Many minor fixes and improvements.

1. dicm2nii can save SPM style NIfTI;
2. nii_tool can convert between 3D and 4D NIfTI;
3. many other fixes and improvements.

1. Include new file nii_tool.m, which can read/write almost any datatype of NIfTI files with different versions;
2. dicm_img returns the same as dicomread by default (transposed img);
3. Include pigz for Windows and Linux for fast gz (de)compression.

1. Fix error for multiframe dicom with single frame;
2. Make number of slices detection more reliable;
3. Other minor improvements.

1. Use ImagePositionPatient to derive SliceThickness if possible;
2. Override number of slices in dicom header with unique ImagePositionPatient;
3. Add RescaleIntercept and RescaleSlope consistency check.

See previous update

1. Use parallel tool if available and worthy;
2. First tested version for Octave 3.8.1(GUI not working);
3. Some minor fixes.

1. bug fix for missing number of slices in GE multiframe dicom;
2. sort_dicm takes care of multiple StudyID;
3. minor improvements on dicm2nii, dicm_hdr and dicm_dict.

Optional output argument for sort_dicm

1. Include new file sort_dicm, which sorts files for different subjects into sub-folders;
2. Remember the GUI setting from last conversion;
3. Other minor improvements.

Take care of different carriage return issue in Philips PAR file

1. Take care of missing VR by some 3rd party dicom converter;
2. some minor improvements.

1. Fix the problem caused by PAR 4.2 keyword case change;
2. Ignore PAR file extension case.

1. can deal with compressed tgz, tar file
2. some minor fixes

1. Take care of non-unique ixyz;
2. Bug fix for slice_code for interleaved descending;
3. Bug fix for GE interleaved file order;
4. Store readout for DTI.

1. Image storage change to make DTI data work for FSL 5.05 and later
2. Change phase direction in image space for FSL
3. Use ProtocolName for Siemens data
4. GE data: can get phase direction for later version; take care of interleaved numbering

1. Fix to work for new GE data, including DTI;
2. Improved multi-subject data conversion;
3. Better file name for GE/Philips data;
4. Many minor fix and improvement.

Not set cal_min and cal_max anymore, so avoid display range problem.

1. Store FSL slice timing in dcmHeaders.mat;
2. Implement slice timing for multiband dicom;
3. Bug fix for slice order for some GE data;
4. Other minor improvements;

1. bug fix for MoCo series detection;
2. bug fix in rename_dicm: missing Manufacturer

1. Support dicom without meta info;
2. Bug fix for gzip.m detection;
3. Fix problem with ~ as home folder;
4. Improvement for error info file.

1. skip missing file check;
2. Allow missing files at the beginning of a series.
1. Bug fix for DTI parameter parsing;
2. Also save error info into a file;
3. Other minor improvements.

1. Bug fix and improvement for DTI parameters.
2. Deal Philip multi-frame B0 map correctly.
3. Great speed improvement for multi-frame dicom.

1. Implement conversion for AFNI HEAD/BRIK files.
2. Bug fixes for dealing with current folder as src folder etc.

1. Minor improvement for dicm_hdr: read V4.1 PAR file correctly;
2. Make some MRI parameter non-mandatory, so may work for other modality.

1. Support implicit VR dicom;
2. Make dicm_hdr, dicm_img and dicm_dict available to users by extracting them from dicm2nii. Add rename_dicm.
3. Improve dicm_hdr

1. First working version for Philips multiframe dicom
2. Some tweaks to dicm_hdr
3. Minor bug fixes

1. Works for Siemens non-mosaic DTI data too.
2. Make xform matrix robust, aiming to work for Philips single dicom file (no data for test though).
3. dicm_hdr can decode SQ now.
4. Avoid fullfile, since it doesn't accept cellstr in older Matlab.

Major: first implementation for conversion of GE and Philips data.
Minor: remove dependency on normc, etc.

Bug fix for DTI bval/bvec files introduced in last update

1. Try and suggest to use pigz for gz compression
2. Fix the missing-field error for DTI data with more that one excitations.
3. Protect GUI from command line plotting.

A bug fix for '*' input, and some minor improvement for dicom header reading

Some SPM users may not have Imaging Processing Toolbox. This update removed this dependency. This also speeds up the dicom header parsing.

1. File name is changed from dcm2nii.m to dicm2nii.m. This will avoid confusion with MRICron's dcm2nii converter.
2. GUI is implemented.
3. Bug fix for cellstr input for multiple files.

1. Allow to specify a subjectID for nii;
2. Accept more input source options, like 1 or more dicom files, or wildcard like run1*.dcm;
3. Include related NIfTI toolbox code in the m file for easy distribution.

Some minor improvement for the code. Add a line for usage.

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.