Index

Name

mri_convert

Description

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.

Synopsis

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

Arguments

Positional Arguments

involume

Input volume

outvolume

Output volume

Required Flagged Arguments

None

Optional Flagged Arguments

Flag

Description

-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

see SPECIFYING THE ORIENTATION

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

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

--sphinx

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

See SETTING ORIENTATION

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

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

--bfile-little-endian

Write out bshort/bfloat files in little endian

--in_stats_table

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

--out_stats_table

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

-nth

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 TI

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

--slice-reverse

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:

cor

MGH-NMR COR format (deprecated)

mgh

MGH-NMR format

mgz

MGH-NMR gzipped (compressed) mgh format

minc

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

analyze

3D analyze (same as spm )

analyze4d

4D analyze

spm

SPM Analyze format (same as analyze and analyze3d)

ge

GE Genesis format (input only)

gelx

GE LX (input only)

lx

Same as gelx

ximg

GE XIMG variant (input only)

siemens

Siemens IMA (input only)

dicom

Generic DICOM format (input only)

siemens_dicom

Siemens DICOM format (input only)

afni

AFNI format

brik

Same as afni

bshort

MGH-NMR bshort format

bfloat

MGH-NMR bfloat format

sdt

Varian

outline

MGH-NMR outline format

otl

Same as outline

gdf

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

nifti1

NIfTI-1 volume (separate image and header files)

nii

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.

--ascii

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

--ascii+crsf

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

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)

--mid-frame

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

-roi

-fp or --fill_parcellation

-sp or --smooth_parcellation

-zo or --zero_outlines

-cf or --color_file

-nt or --no_translate

--status

Status file for DICOM conversion

--sdcmlist

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)

--sphinx

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.

Outputs

outvolume

Output volume

Additional Information

https://surfer.nmr.mgh.harvard.edu/pub/docs/html/mri_convert.help.xml.html

See Also

mris_convert

Reporting Bugs

Report bugs to < analysis-bugs@nmr.mgh.harvard.edu >

Author/s

DougGreve, BruceFischl

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