mri_convert is a general purpose utility for converting between different file formats. The file type can be specified in two ways. First, mri_convert will try to figure it out on its own from the format of the file name (eg, files that end in .img are assumed to be in spm analyze format). Second, the user can explicity set the type of file using --in_type and/or --out_type.

Legal values for --in_tye (-it) and --out_type (-ot) are listed under optional flagged arguments.

A note on specifying orientation:

Do not use this to try to change the orientation for FSL. This is only to be used when the orientation information in the input file is *wrong*. If it is correct, this will make it wrong! If you are having problems with fslview displaying your data, consult the FSL website for methods to reorient.

Ideally, the orientation information is derived from a DICOM file so that you have some confidence that it is correct. It is generally pretty easyto determine which direction Anterior/Posterior or Inferior/Superior are. Left/Right is very difficult. However, if you have some way of knowing which direction is which, you can use these options to incorporate this information into the header of the output format. For analyze files, it will be stored in the output.mat file. For NIFTI, it is stored as the qform matrix. For bshort/bfloat, it is stored in the .bhdr file. For mgh/mgz it is internal. First of all, determining and setting the orientation is hard. Don't fool yourself into thinking otherwise. Second, don't think you are going to learn all you need to know from this documentation. Finally, you risk incorporating a left-right flip in your data if you do it incorrectly. OK, there are two ways to specify this information on the command-line. (1) explicitly specify the direction cosines with -iid, -ijd, -ikd. If you don't know what a direction cosine is, don't use this method. (2) specify an orientation string with --in_orientation ostring and --out_orientation ostring Supply the orientation information in the form of an orientation string (ostring). The ostring is three letters that roughly describe how the volume is oriented. This is usually described by the direction cosine information as originally derived from the dicom but might not be available in all data sets. You'll have to determine the correct ostring for your data. The first character of ostring determines the direction of increasing column. The second character of ostring determines the direction of increasing row. The third character of ostring determines the direction of increasing slice. Eg, if the volume is axial starting inferior and going superior the slice is oriented such that nose is pointing up and the right side of the subject is on the left side of the image, then this would correspond to LPS, ie, as the column increases, you move to the patients left; as the row increases, you move posteriorly, and as the slice increases, you move superiorly. Valid letters are L, R, P, A, I, and S. There are 48 valid combinations (eg, RAS LPI, SRI). Some invalid ones are DPS (D is not a valid letter), RRS (can't specify R twice), RAP (A and P refer to the same axis). Invalid combinations are detected immediately, an error printed, and the program exits. Case-insensitive. Note: you can use tkregister2 to help determine the correct orientation string.


mri_convert [options] <in volume> <out volume>


Positional Arguments


Input volume


Output volume

Required Flagged Arguments


Optional Flagged Arguments



-ro or --read_only

-nw or --no_write

-ii or --in_info

-oi or --out_info

-is or --in_stats

Print statistics on input volume

-os or --out_stats

Print statistics on output volume

-im or --in_matrix

-om or --out_matrix

-upsample N <size>

Reduce voxel size by a factor of N in all dimensions

-iis or --in_i_size <size>

-ijs or --in_j_size <size>

-ikd or --in_k_size <size>

--in_orientation orientation-string


-ic or --in_center <R coordinate> <A coordinate> <S coordinate>

-dic or --delta_in_center <dR coordinate> <dA coordinate> <dS coordinate>


Change orientation info to sphinx

-oni or -oic or --out_i_count <count>

-onj or -ojc or --out_j_count <count>

-onk or -okc or --out_k_count <count>

-oid or --out_i_direction <R direction> <A direction> <S direction>

-ojd or --out_j_direction <R direction> <A direction> <S direction>

-okd or --out_k_direction <R direction> <A direction> <S direction>

--out_orientation orientation-string


-oc or --out_center <R direction> <A direction> <S direction>

-odt or --out_data_type <uchar|short|int|float>


Write out bshort/bfloat files in little endian


Input data is a stats table as produced by asegstats2table or aparcstats2table


Output data is a stats table (use --like to pass template table for measure, columns, and rows heads)

-rt or --resample_type <interpolate|weighted|nearest|cubic>

Default is interpolate


Specify frame number

--no_scale flag <-ns>

1 means don't rescale values for COR

-nc or --nochange

Don't change type of input to that of template

-tr TR

TR in msec

-te TE

TE in msec


TI in msec (note uppercase flag)

-flip_angle flip angle

Angle in radians

--autoalign mtxfile

Text file with autoalign matrix

-oval val

--outside_val val

Set the values outside of the image that may rotate in if a transform is applied to val

Applying Transforms Flagged Arguments

--apply_transform xfmfile (-T or -at)

Apply transform given by xfm or m3z files. The volume can be resampled into another space by supplying a transform using the -apply_transform flag. This reads the transform file and applies the transform (when --apply_inverse_transform is used, the transform is inverted an then applied). An example of a transform file is talairach.xfm as found in subjectid/mri/transforms. To convert a subject's orig volume to talairach space, execute the following lines: cd subjectid/mri , mkdir talairach, mri_convert orig.mgz --apply_transform transforms/talairach.xfm -oc 0 0 0 orig.talairach.mgz. This properly accounts for the case where the input volume does not have it's coordinate center at 0. To evaluate the result, run: tkmedit -f $SUBJECTS_DIR/talairach/mri/orig.mgz -aux orig.talairach.mgz . The main and aux volumes should overlap very closely. If they do not, use tkregister2 to fix it.

--apply_inverse_transform xfmfile (-ait)

Apply inverse transform given by xfm or m3z files.

--devolvexfm subjectid

--like name

Output is embedded in a volume like name, or in stats-table like name (measure, columns, rows)

--crop <x> <y> <z>

Crop to 256 around center (x,y,z)

--cropsize <dx> <dy> <dz>

Crop to size <dx, dy, dz>

--cutends ncut

Remove ncut slices from the ends

--slice-crop s_start s_end

Keep slices s_start to s_end


Reverse order of slices, update vox2ras

--nslices-override nslices

Use this number of slices when converting DICOM mosaics

--slice-bias alpha

Apply half-cosine bias field

--fwhm fwhm

Smooth input volume by fwhm mm

Specifying the Input and Output File Types

Legal values for --in_type (-it) and --out_type (-ot) are:


MGH-NMR COR format (deprecated)


MGH-NMR format


MGH-NMR gzipped (compressed) mgh format


MNI's Medical Imaging NetCDF format (output may not work)


3D analyze (same as spm )


4D analyze


SPM Analyze format (same as analyze and analyze3d)


GE Genesis format (input only)


GE LX (input only)


Same as gelx


GE XIMG variant (input only)


Siemens IMA (input only)


Generic DICOM format (input only)


Siemens DICOM format (input only)


AFNI format


Same as afni


MGH-NMR bshort format


MGH-NMR bfloat format




MGH-NMR outline format


Same as outline


GDF volume (requires image stem for output; use -gis)


NIfTI-1 volume (separate image and header files)


NIfTI-1 volume (single file). If the input/output has extension .nii.gz, then compressed is used.

Converting to SPM-Analyze Format

Converting to SPM-Analyze format can be done in two ways, depending upon whether a single frame or multiple frames are desired. For a single frame, simply specify the output file name with a .img extension, and mri_convert will save the first frame into the file. For multiple frames, specify the base as the output file name and add --out_type spm. This will save each frame as baseXXX.img where XXX is the three-digit, zero-padded frame number. Frame numbers being at one. By default, the width of the zero padding is 3. This can be controlled with --in_nspmzeropad N where N is the new width.


Save output as ascii. This will be a data file with a single column of data. The fastest dimension will be col, then row, then slice, then frame


Same as --ascii but includes col, row, slice, and frame

-r or --reorder olddim1 olddim2 olddim3

-r4 or --reorder4 olddim1 olddim2 olddim3 olddim4

Reorder axes such that olddim1 is the new column dimensions, olddim2 is the new row dimension, olddim3 is the new slice, and olddim4 is the new frame dimension. Example: 2 1 3 will swap row and colms. If using -r4, the output geometry will likely be wrong. It is best to re-run mri_convert and specify a correctly orientated volume through the --in_like option

--invert_contrast threshold

All voxels in volume greater than threshold are replaced with 255-value. Only makes sense for 8 bit images. Only operates on first frame.

-i or --input_volume

-o or --output_volume

-c or --conform

Conform to 1mm voxel size in coronal slice direction with 256^3 or more.

-cm or --conform_min

Conform to the src min direction size

-cs or --conform_size size_in_mm

conform to the size given in mm

-po or --parse_only

-is or --in_stats

-os or --out_stats

-ro or --read_only

-nw or --no_write

-sn or --subject_name

-rl or --reslice_like

-tt or --template_type <type>


Split output frames into separate output files. Example: mri_convert a.nii b.nii --split will create b0000.nii b0001.nii b0002.nii ...

--erode-seg Nerodes

Erode segmentation boundaries Nerode times (based on 6 nearest neighbors)

--dil-seg Ndilations

Dilate segmentation boundaries Ndilate times (based on 6 nearest neighbors) to fill seg=0 voxels

--dil-seg-mask mask

Dilate segmentation boundaries to fill mask

-f or --frame frameno [...]

Keep only 0-based frame number(s)


Keep only the middle frame

--nskip n

Skip the first n frames

--ndrop n

Drop the last n frames

--fsubsample start delta end

Frame subsampling (end = -1 for end)

--sc or --scale factor

Input intensity scale factor

-osc or --out-scale factor

Output intensity scale factor

-il or --in_like


-fp or --fill_parcellation

-sp or --smooth_parcellation

-zo or --zero_outlines

-cf or --color_file

-nt or --no_translate


Status file for DICOM conversion


List of DICOM files for conversion

-ti or --template_info

Dump info about template

-gis <gdf image file stem>

-cg or --crop_gdf

Apply GDF cropping

-zgez or --zero_ge_z_offset

Set c_s=0 (appropriate for dicom files from GE machines with isocenter scanning)


Reorient to sphinx the position. This function is applicable when the input geometry information is correct but the subject was in the scanner in the 'sphinx' position (ie AP in line with the bore) instead of head-first-supine (HFS). This is often the case with monkeys. Note that the assumption is that the geometry information in the input file is otherwise accurate.



Output volume

Additional Information

See Also


Reporting Bugs

Report bugs to < >


DougGreve, BruceFischl

mri_convert (last edited 2017-11-29 12:05:15 by MorganFogarty)