dcm2niix looks like a small tool from the outside: one command, one folder, some output files. The options are where its real power lives. A handful of flags control compression, filenames, output location, series selection, slice merging, vendor scaling, and BIDS sidecars, and knowing them turns a basic conversion into a workflow you can trust. This guide explains every important option in plain terms, with examples you can copy, so you can stop guessing and start choosing deliberately.
The basic shape of a command
Every dcm2niix command follows the same shape: options first, input folder last. The input is the final value you provide, and it is either a folder holding DICOM data or a single DICOM file. When you give a folder, dcm2niix searches it and its subfolders recursively, so a whole session converts in one run.
A full featured example looks like this:
dcm2niix -z y -f myMRI%s -o /users/chris/outdir /users/chris/dir
Each flag in that line earns its place, and the sections below explain what each one does and when you would change it.
Compression: -z and the numbered levels
The -z option controls gzip compression of the NIfTI output. Use -z y for compressed.nii.gz files or -z n for plain.nii files. Compressed files are much smaller, which matters when a study holds hundreds of scans, and most modern tools read.nii.gz directly. Some older tools, though, expect plain.nii, so if a downstream program complains that it cannot read your files, -z n is the first thing to try.
You can also pick a compression level with the numbered options -1 through -9. Level 1 is the fastest and produces larger files, while level 9 squeezes the smallest files at the cost of time. For most work, plain -z y with its default level is the right balance, and you will only reach for the numbered levels when disk space or speed becomes a real constraint.
Filenames: -f and its format codes
The -f option sets the output filename pattern, and it is the option that most affects how organized your project feels. The pattern uses codes that dcm2niix replaces for each series:
- %f is the input filename
- %p is the protocol name
- %s is the series number
- %z is the sequence name, taken from DICOM tag 0018,0024, so a T1 scan converted with “myName%z” might yield “myNameT1”
A pattern like -f “myMRI%s” gives you myMRI33 for the 33rd series. A BIDS style pattern like -f “%f_%p_%s” builds names from the input filename, protocol, and series number. Choose a pattern that stays unique across series and readable to a human, because you will live with these names through the whole analysis.
If you run the MRIcroGL converter GUI, it shows a live example of the filenames your pattern will produce. That preview is genuinely useful: check it once before a big batch, and you will avoid a folder full of confusing names.
Output location: -o
The -o option sets the output directory. If you leave it out, converted files go into the input folder alongside the DICOM. That default is handy for a quick test and messy for real work. A dedicated output folder keeps raw and converted data apart, which makes sharing, backing up, and cleaning up far simpler.
There is one case where -o is not optional: when your DICOM lives on read only media, such as a disc or a locked archive. dcm2niix cannot write next to files it cannot modify, so you must point output somewhere writable. Make -o a habit and you will never hit that wall.
Series selection: -n
The -n option converts only one series. Give it a series number, like -n 12, and only the twelfth series is converted. This is useful when a folder holds many series and you only need one, or when you want to test settings on a single series before converting everything.
Its most useful trick is the negative form. Run -n -1 and dcm2niix reports the series numbers available in the folder but converts nothing. That makes it the perfect inspection tool for an unfamiliar dataset: list first, then convert exactly what you want.
Merging slices: -m
The -m option controls whether 2D slices from the same series are merged into a single NIfTI image. With -m y, slices are stacked into one image regardless of differences in study time, echo, coil, or orientation. With -m n, images are kept separate based on those attributes.
Which you want depends on your vendor and your sequence. Some scanners split what is really one acquisition across slice groups, and merging gives you the correct volume. Other times, merging glues together things that should stay apart, like different echoes. If a conversion produces volumes that look merged wrong or split wrong, -m is the first flag to flip, and comparing both results usually settles it fast.
Vendor and metadata options: -p, -b, -ba
Three more flags round out the set you will use most:
- -p y/n controls Philips precision scaling. If Philips data looks scaled wrong, washed out or oddly bright, try -p y.
- -b y/n controls the BIDS JSON sidecar. It defaults to y, and you want to keep it that way for any BIDS or fMRIPrep work, since those pipelines read metadata from the sidecar.
- -ba y/n controls anonymization of the BIDS sidecar, also defaulting to y. It helps keep identifying details out of the sidecar, which matters whenever data leaves your secured system.
Run dcm2niix -h any time you want the full list. The help screen is short, readable, and the fastest reference you have.
Defaults file: dcm2nii.ini
If you find yourself typing the same flags every time, the defaults file is your friend. dcm2nii.ini holds default compression and filename settings, and it is created on your first run. Edit it with a text editor to change your defaults permanently. On macOS, for example, you can open it with TextEdit from your home folder. Once your defaults match your lab convention, your daily commands get much shorter.
Putting it together
Here is a sensible progression for learning the flags. Start with the minimal command and check the output. Add -o to control where results go. Add -f to control names. Add -z y for compression. Then, only when a dataset demands it, reach for -n to pick a series, -m to fix merging, and -p to fix Philips scaling. Most days you will use the first four flags and leave the rest alone, and that is exactly how it should be. The options exist for the awkward cases, not to complicate the easy ones.
Combining flags safely
Flags combine freely, but a few combinations deserve a second thought. Compression and filename patterns never conflict, so -z y with any -f pattern is always safe. Series selection with -n pairs well with testing: pick one series, try a merge or scaling setting, and check the result before converting the rest. The combination to handle carefully is -m y with multi echo data, since merging across echoes can hide structure you wanted to keep. When in doubt, convert once with each setting into separate output folders and compare the results before you commit to one. Disk space is cheap, but a wrongly merged dataset is expensive to redo.
Conclusion
dcm2niix options are a small set with a big effect. Compression (-z), filenames (-f), output folder (-o), series selection (-n), slice merging (-m), Philips scaling (-p), and the BIDS flags (-b, -ba) cover nearly every conversion decision you will face. Learn the typical explicit command, use -n -1 to inspect unfamiliar folders, and save your favorite defaults in dcm2nii.ini. With those habits, conversion stops being a guessing game and becomes a reliable step you barely think about.
Read next:
