【MRtrix】NIfTI形式からMIF形式の変換


1. 目的
2. MIF形式とは
3. コマンド
4. 使用例
4.1. NIfTI形式からMIF形式に変換
4.2. MIF形式からNIfTI形式に変換
5. おまけ


1. 目的

  • NIfTI形式からMIF形式の変換

2. MIF形式とは

MIF形式は、MRtrixで使われる画像フォーマットでNIfTIとは異なり、MPGの軸情報(gradient table)やDICOMヘッダー情報が格納されたJSONファイルを組み込むことができる。

3. コマンド

NIfTI形式からMIF形式の変換には、MRtrixのmrconvertを用いる。

mrconvertのヘルプは、次の通り。

クリックして展開
SYNOPSIS

     Perform conversion between different file types and optionally extract a
     subset of the input image

USAGE

     mrconvert [ options ] input output

        input        the input image.

        output       the output image.


DESCRIPTION

     If used correctly, this program can be a very useful workhorse. In
     addition to converting images between different formats, it can be used to
     extract specific studies from a data set, extract a specific region of
:...skipping...
MRtrix 3.0.0-40-g3e1ed225           mrconvert                        Jun 18 2020

     mrconvert: part of the MRtrix3 package

SYNOPSIS

     Perform conversion between different file types and optionally extract a
     subset of the input image

USAGE

     mrconvert [ options ] input output

        input        the input image.

        output       the output image.


DESCRIPTION

     If used correctly, this program can be a very useful workhorse. In
     addition to converting images between different formats, it can be used to
     extract specific studies from a data set, extract a specific region of
     interest, or flip the images. Some of the possible operations are
     described in more detail below.

     Note that for both the -coord and -axes options, indexing starts from 0
     rather than 1. E.g. -coord 3 <#> selects volumes (the fourth dimension)
     from the series; -axes 0,1,2 includes only the three spatial axes in the
     output image.

     Additionally, for the second input to the -coord option and the -axes
     option, you can use any valid number sequence in the selection, as well as
     the 'end' keyword (see the main documentation for details); this can be
     particularly useful to select multiple coordinates.

     The -vox option is used to change the size of the voxels in the output
     image as reported in the image header; note however that this does not
     re-sample the image based on a new voxel size (that is done using the
     mrresize command).

     By default, the intensity scaling parameters in the input image header are
     passed through to the output image header when writing to an integer
     image, and reset to 0,1 (i.e. no scaling) for floating-point and binary
     images. Note that the -scaling option will therefore have no effect for
     floating-point or binary output images.

     The -axes option specifies which axes from the input image will be used to
     form the output image. This allows the permutation, omission, or addition
     of axes into the output image. The axes should be supplied as a
     comma-separated list of axis indices. If an axis from the input image is
     to be omitted from the output image, it must either already have a size of
     1, or a single coordinate along that axis must be selected by the user by
     using the -coord option. Examples are provided further below.

     The -bvalue_scaling option controls an aspect of the import of diffusion
     gradient tables. When the input diffusion-weighting direction vectors have
     norms that differ substantially from unity, the b-values will be scaled by
     the square of their corresponding vector norm (this is how multi-shell
     acquisitions are frequently achieved on scanner platforms). However in
     some rare instances, the b-values may be correct, despite the vectors not
     being of unit norm (or conversely, the b-values may need to be rescaled
     even though the vectors are close to unit norm). This option allows the
     user to control this operation and override MRrtix3's automatic detection.

EXAMPLE USAGES

     Extract the first volume from a 4D image, and make the output a 3D image:
       $ mrconvert in.mif -coord 3 0 -axes 0,1,2 out.mif
     The -coord 3 0 option extracts, from axis number 3 (which is the fourth
     axis since counting begins from 0; this is the axis that steps across
     image volumes), only coordinate number 0 (i.e. the first volume). The
     -axes 0,1,2 ensures that only the first three axes (i.e. the spatial axes)
     are retained; if this option were not used in this example, then image
     out.mif would be a 4D image, but it would only consist of a single volume,
     and mrinfo would report its size along the fourth axis as 1.

     Extract slice number 24 along the AP direction:
       $ mrconvert volume.mif slice.mif -coord 1 24
     MRtrix3 uses a RAS (Right-Anterior-Superior) axis convention, and
     internally reorients images upon loading in order to conform to this as
     far as possible. So for non-exotic data, axis 1 should correspond
     (approximately) to the anterior-posterior direction.

     Extract only every other volume from a 4D image:
       $ mrconvert all.mif every_other.mif -coord 3 1:2:end
     This example demonstrates two features: Use of the colon syntax to
     conveniently specify a number sequence (in the format 'start:step:stop');
     and use of the 'end' keyword to generate this sequence up to the size of
     the input image along that axis (i.e. the number of volumes).

     Alter the image header to report a new isotropic voxel size:
       $ mrconvert in.mif isotropic.mif -vox 1.25
     By providing a single value to the -vox option only, the specified value
     is used to set the voxel size in mm for all three spatial axes in the
     output image.

     Alter the image header to report a new anisotropic voxel size:
       $ mrconvert in.mif anisotropic.mif -vox 1,,3.5
     This example will change the reported voxel size along the first and third
     axes (ideally left-right and inferior-superior) to 1.0mm and 3.5mm
     respectively, and leave the voxel size along the second axis (ideally
     anterior-posterior) unchanged.

     Turn a single-volume 4D image into a 3D image:
       $ mrconvert 4D.mif 3D.mif -axes 0,1,2
     Sometimes in the process of extracting or calculating a single 3D volume
     from a 4D image series, the size of the image reported by mrinfo will be
     "X x Y x Z x 1", indicating that the resulting image is in fact also 4D,
     it just happens to contain only one volume. This example demonstrates how
     to convert this into a genuine 3D image (i.e. mrinfo will report the size
     as "X x Y x Z".

     Insert an axis of size 1 into the image:
       $ mrconvert XYZD.mif XYZ1D.mif -axes 0,1,2,-1,3
     This example uses the value -1 as a flag to indicate to mrconvert where a
     new axis of unity size is to be inserted. In this particular example, the
     input image has four axes: the spatial axes X, Y and Z, and some form of
     data D is stored across the fourth axis (i.e. volumes). Due to insertion
     of a new axis, the output image is 5D: the three spatial axes (XYZ), a
     single volume (the size of the output image along the fourth axis will be
     1), and data D will be stored as volume groups along the fifth axis of the
     image.

     Manually reset the data scaling parameters stored within the image header
     to defaults:
       $ mrconvert with_scaling.mif without_scaling.mif -scaling 0.0,1.0
     This command-line option alters the parameters stored within the image
     header that provide a linear mapping from raw intensity values stored in
     the image data to some other scale. Where the raw data stored in a
     particular voxel is I, the value within that voxel is interpreted as:
     value = offset + (scale x I).  To adjust this scaling, the relevant
     parameters must be provided as a comma-separated 2-vector of
     floating-point values, in the format "offset,scale" (no quotation marks).
     This particular example sets the offset to zero and the scale to one,
     which equates to no rescaling of the raw intensity data.

Options for manipulating fundamental image properties

  -coord axis selection  (multiple uses permitted)
     retain data from the input image only at the coordinates specified in the
     selection along the specified axis. The selection argument expects a
     number sequence, which can also include the 'end' keyword.

  -vox sizes
     change the voxel dimensions reported in the output image header

  -axes axes
     specify the axes from the input image that will be used to form the output
     image

  -scaling values
     specify the data scaling parameters used to rescale the intensity values

Options for handling JSON (JavaScript Object Notation) files

  -json_import file
     import data from a JSON file into header key-value pairs

  -json_export file
     export data from an image header key-value pairs into a JSON file

Options to modify generic header entries

  -clear_property key  (multiple uses permitted)
     remove the specified key from the image header altogether.

  -set_property key value  (multiple uses permitted)
     set the value of the specified key in the image header.

  -append_property key value  (multiple uses permitted)
     append the given value to the specified key in the image header (this adds
     the value specified as a new line in the header value).

  -copy_properties source
     clear all generic properties and replace with the properties from the
     image / file specified.

Stride options

  -strides spec
     specify the strides of the output data in memory; either as a
     comma-separated list of (signed) integers, or as a template image from
     which the strides shall be extracted and used. The actual strides produced
     will depend on whether the output image format can support it.

Data type options

  -datatype spec
     specify output image data type. Valid choices are: float32, float32le,
     float32be, float64, float64le, float64be, int64, uint64, int64le,
     uint64le, int64be, uint64be, int32, uint32, int32le, uint32le, int32be,
     uint32be, int16, uint16, int16le, uint16le, int16be, uint16be, cfloat32,
     cfloat32le, cfloat32be, cfloat64, cfloat64le, cfloat64be, int8, uint8,
     bit.

DW gradient table import options

  -grad file
     Provide the diffusion-weighted gradient scheme used in the acquisition in
     a text file. This should be supplied as a 4xN text file with each line is
     in the format [ X Y Z b ], where [ X Y Z ] describe the direction of the
     applied gradient, and b gives the b-value in units of s/mm^2. If a
     diffusion gradient scheme is present in the input image header, the data
     provided with this option will be instead used.

  -fslgrad bvecs bvals
     Provide the diffusion-weighted gradient scheme used in the acquisition in
     FSL bvecs/bvals format files. If a diffusion gradient scheme is present in
     the input image header, the data provided with this option will be instead
     used.

  -bvalue_scaling mode
     enable or disable scaling of diffusion b-values by the square of the
     corresponding DW gradient norm (see Desciption). Valid choices are yes/no,
     true/false, 0/1 (default: automatic).

DW gradient table export options

  -export_grad_mrtrix path
     export the diffusion-weighted gradient table to file in MRtrix format

  -export_grad_fsl bvecs_path bvals_path
     export the diffusion-weighted gradient table to files in FSL (bvecs /
     bvals) format

Options for importing phase-encode tables

  -import_pe_table file
     import a phase-encoding table from file

  -import_pe_eddy config indices
     import phase-encoding information from an EDDY-style config / index file
     pair

Options for exporting phase-encode tables

  -export_pe_table file
     export phase-encoding table to file

  -export_pe_eddy config indices
     export phase-encoding information to an EDDY-style config / index file
     pair

Standard options

  -info
     display information messages.

  -quiet
     do not display information messages or progress status; alternatively,
     this can be achieved by setting the MRTRIX_QUIET environment variable to a
     non-empty string.

  -debug
     display debugging messages.

  -force
     force overwrite of output files (caution: using the same file as input and
     output might cause unexpected behaviour).

  -nthreads number
     use this number of threads in multi-threaded applications (set to 0 to
     disable multi-threading).

  -config key value  (multiple uses permitted)
     temporarily set the value of an MRtrix config file entry.

  -help
     display this information page and exit.

  -version
     display version information and exit.

基本的な使い方は、次の通り。

mrconvert <入力画像(.nii)> <出力画像(.mif)>  # 基本
mrconvert  -fslgrad <b-vectorファイル> <b-valueファイル> <入力画像(.nii)> <出力画像(.mif)>  # DICOMヘッダー情報(JSONファイル)を組み込む
mrconvert  -json_import  <JSONファイル> <入力画像(.nii)> <出力画像(.mif)>  # MPG軸情報(gradient table)を組み込む

4. 使用例

4.1. NIfTI形式からMIF形式に変換

拡散MRI(DWI.nii.gz)とそのMPG軸情報(bvecs, bvals)とヘッダー情報(headers.json)を用意する。MPG軸情報とヘッダー情報が書かれたJSONファイルの取得には、dcm2niixを用いるとよい。dcm2niixの使い方は、こちらの記事を参考にするとよい。

拡散MRI(DWI.nii.gz)とそのMPG軸情報(bvecs, bvals)とヘッダー情報(headers.json)をまとめて、MIF形式(DWI.mif)に変換する。

mrconvert -fslgrad bvecs bvals -json_import headers.json DWI.nii.gz DWI.mif

変換したMIFファイル(DWI.mif)の情報を、mrinfoコマンドで確認する。

mrinfo DWI.mif

ヘッダー情報やMPG軸情報にいたるまで、詳細な情報を持っていることが分かる。

    ************************************************
    Image name:          "DWI.mif"
    ************************************************
    Dimensions:        130 x 130 x 82 x 129
    Voxel size:        1.76923 x 1.76923 x 1.8 x 4.9
    Data strides:      [ -1 2 3 4 ]
    Format:            MRtrix
    Data type:         signed 16 bit integer (little endian)
    Intensity scaling: offset = 0, multiplier = 1
    Transform:                    1           0          -0        -109
                                  0           1          -0      -103.7
                                 -0           0           1      -58.57
    AcquisitionMatrixPE: 130
    AcquisitionNumber: 1
    AcquisitionTime:   20:32:46.875000
    BandwidthPerPixelPhaseEncode: 26.0760002
    BaseResolution:    130
    BodyPartExamined:  BRAIN
    ConsistencyInfo:   N4_VE11C_LATEST_20160120
    ConversionSoftware: dcm2niix
    ConversionSoftwareVersion: v1.0.20171215 (OpenJPEG build) GCC7.3.0
    DerivedVendorReportedEchoSpacing: 0.000589990988
    DeviceSerialNumber: 66084
    DwellTime:         1.79999995e-06
    EchoTime:          Anonymized
    EchoTrainLength:   Anonymized
    EffectiveEchoSpacing: 0.000294995989
    FlipAngle:         Anonymized
    ImageOrientationPatientDICOM: 1,0,0,0,1,0
    ImageType:         ORIGINAL
    [7 entries]        PRIMARY
                       ...
                       NORM
                       MOSAIC
    InPlanePhaseEncodingDirectionDICOM: COL
    InstitutionAddress: Anonymized
    InstitutionName:   Anonymized
    InstitutionalDepartmentName: Anonymized
    MRAcquisitionType: 2D
    MagneticFieldStrength: 3
    Manufacturer:      Siemens
    ManufacturersModelName: Prisma
    Modality:          MR
    MultibandAccelerationFactor: Anonymized
    ParallelReductionFactorInPlane: 2
    PartialFourier:    0.875
    PatientPosition:   HFS
    PercentPhaseFOV:   100
    PhaseEncodingDirection: j-
    PhaseEncodingSteps: Anonymized
    PhaseResolution:   1
    PixelBandwidth:    Anonymized
    ProcedureStepDescription: Anonymized
    ProtocolName:      diff_1.8mm
    PulseSequenceDetails: %SiemensSeq%_ep2d_diff
    ReceiveCoilActiveElements: HC1-7
    ReceiveCoilName:   HeadNeck_64
    ReconMatrixPE:     Anonymized
    RepetitionTime:    Anonymized
    SAR:               0.234911993
    ScanOptions:       PFP_FS
    ScanningSequence:  EP
    SequenceName:      _ep_b0
    SequenceVariant:   SK_SP
    SeriesDescription: diff_1.8mm
    SeriesNumber:      6
    ShimSetting:       -3840,8483,-1761,409,3,-240,21,-12
    SliceThickness:    1.79999995
    SliceTiming:       2.3825,0,2.5,0.12,2.62,0.24,2.7375,0.3575,2.8575,0.4775,2.9775,0.595,3.095,0.715,3.215,0.835,3.3325,0.9525,3.4525,1.0725,3.5725,1.1925,3.69,1.31,3.81,1.43,3.93,1.5475,4.0475,1.6675,4.1675,1.7875,4.285,1.905,4.405,2.025,4.525,2.1425,4.6425,2.2625,4.7625,2.3825,0,2.5,0.12,2.62,0.24,2.7375,0.3575,2.8575,0.4775,2.9775,0.595,3.095,0.715,3.215,0.835,3.3325,0.9525,3.4525,1.0725,3.5725,1.1925,3.69,1.31,3.81,1.43,3.93,1.5475,4.0475,1.6675,4.1675,1.7875,4.285,1.905,4.405,2.025,4.525,2.1425,4.6425,2.2625,4.7625
    SoftwareVersions:  syngo_MR_E11
    SpacingBetweenSlices: 1.79999995
    StationName:       Anonymized
    TotalReadoutTime:  0.0381
    TxRefAmp:          248.688004
    command_history:   mrconvert -fslgrad bvecs bvals -json_import headers.json DWI.nii.gz DWI.mif  (version=3.0.0-40-g3e1ed225)
    comments:          TE=70;Time=203246.875;phase=1;mb=2
    dw_scheme:         0,0,0,0
    [129 entries]      -0.9999755033,0,-0.006999486523,1000
                       ...
                       -0.7199790751,0.6071340633,-0.336182035,2000
                       -0.2673210218,0.9602590784,0.08026190655,2000
    mrtrix_version:    3.0.0-40-g3e1ed225

4.2. MIF形式からNIfTI形式に変換

MIF形式からNIfTI形式に変換することもできる。

この時、-export_grad_fslオプションでMPG軸情報(FSLフォーマット)を、-json_exportオプションでヘッダー情報のJSONファイルを出力することができる。

mrconvert -export_grad_fsl bvecs_mif2nii bvals_mif2nii -json_export headers_mif2nii.json DWI.mif DWI_mif2nii.nii.gz

5. おまけ

MIF形式の圧縮もすることができ、その場合、拡張子は「.mif.gz」になる。

mrconvert -fslgrad bvecs bvals -json_import headers.json DWI.nii.gz DWI.mif.gz

Print Friendly, PDF & Email

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください