FSL——FLIRT使用配准与降采样 registration and resample

FSL——FLIRT使用配准与降采样 registration and resample

flirt命令可以用于配准和降采样,最近接触到了这个命令,决定学习一下

Usage: flirt [options] -in <inputvol> -ref <refvol> -out <outputvol>
       flirt [options] -in <inputvol> -ref <refvol> -omat <outputmatrix>
       flirt [options] -in <inputvol> -ref <refvol> -applyxfm -init <matrix> -out <outputvol>

  Available options are:
        -in  <inputvol>                    (no default)
        -ref <refvol>                      (no default)
        -init <matrix-filname>             (input 4x4 affine matrix)
        -omat <matrix-filename>            (output in 4x4 ascii format)
        -out, -o <outputvol>               (default is none)
        -datatype {char,short,int,float,double}                    (force output data type)
        -cost {mutualinfo,corratio,normcorr,normmi,leastsq,labeldiff,bbr}        (default is corratio)
        -searchcost {mutualinfo,corratio,normcorr,normmi,leastsq,labeldiff,bbr}  (default is corratio)
        -usesqform                         (initialise using appropriate sform or qform)
        -displayinit                       (display initial matrix)
        -anglerep {quaternion,euler}       (default is euler)
        -interp {trilinear,nearestneighbour,sinc,spline}  (final interpolation: def - trilinear)
        -sincwidth <full-width in voxels>  (default is 7)
        -sincwindow {rectangular,hanning,blackman}
        -bins <number of histogram bins>   (default is 256)
        -dof  <number of transform dofs>   (default is 12)
        -noresample                        (do not change input sampling)
        -forcescaling                      (force rescaling even for low-res images)
        -minsampling <vox_dim>             (set minimum voxel dimension for sampling (in mm))
        -applyxfm                          (applies transform (no optimisation) - requires -init)
        -applyisoxfm <scale>               (as applyxfm but forces isotropic resampling)
        -paddingsize <number of voxels>    (for applyxfm: interpolates outside image by size)
        -searchrx <min_angle> <max_angle>  (angles in degrees: default is -90 90)
        -searchry <min_angle> <max_angle>  (angles in degrees: default is -90 90)
        -searchrz <min_angle> <max_angle>  (angles in degrees: default is -90 90)
        -nosearch                          (sets all angular search ranges to 0 0)
        -coarsesearch <delta_angle>        (angle in degrees: default is 60)
        -finesearch <delta_angle>          (angle in degrees: default is 18)
        -schedule <schedule-file>          (replaces default schedule)
        -refweight <volume>                (use weights for reference volume)
        -inweight <volume>                 (use weights for input volume)
        -wmseg <volume>                    (white matter segmentation volume needed by BBR cost function)
        -wmcoords <text matrix>            (white matter boundary coordinates for BBR cost function)
        -wmnorms <text matrix>             (white matter boundary normals for BBR cost function)
        -fieldmap <volume>                 (fieldmap image in rads/s - must be already registered to the reference image)
        -fieldmapmask <volume>             (mask for fieldmap image)
        -pedir <index>                     (phase encode direction of EPI - 1/2/3=x/y/z & -1/-2/-3=-x/-y/-z)
        -echospacing <value>               (value of EPI echo spacing - units of seconds)
        -bbrtype <value>                   (type of bbr cost function: signed [default], global_abs, local_abs)
        -bbrslope <value>                  (value of bbr slope)
        -setbackground <value>             (use specified background value for points outside FOV)
        -noclamp                           (do not use intensity clamping)
        -noresampblur                      (do not use blurring on downsampling)
        -2D                                (use 2D rigid body mode - ignores dof)
        -verbose <num>                     (0 is least and default)
        -v                                 (same as -verbose 1)
        -i                                 (pauses at each stage: default is off)
        -version                           (prints version number)
        -help

配准 Registration

配准命令用法

flirt -in invol -ref refvol -out outvol -omat invol2refvol.mat -dof 6

invol 是需要配准的图像, refvol是配准的目标图像,outvol是配准后出书的图像,invol2refvol.mat是变换矩阵,配准的自由度是6

6自由度配准即为刚体配准,不存在线性变换,仅为位移与角度旋转

flirt -in newvol -ref refvol -out outvol -init invol2refvol.mat -applyxfm

添加 -applyxfm可以将之前保存的变换矩阵应用到另一张图像上

降采样

flirt函数可以实现快速降采样

这里的降采样使用配准技术将原分辨率图像改变到目标分辨率下,同时改变了图像矩阵的大小

为了保证图像矩阵的大小可以使用两次变换,先进行降采样,然后再次上采样从而保证图像矩阵大小不变

如果没有目标图像的分辨率的参考图像的话可以自己使用fsl命令进行生成,flirt命令的降采样不需要图像的幅值与目标图像相同,只需要图像的分辨率与大小与目标图像相同

这里的降采样过程中会自动使用高斯模糊对于降采样前的图像进行模糊处理,高斯模糊的sigma值为0.425倍的下采样倍数,对于图片有很好的去噪效果。如果不需要进行去噪平滑的,可以选用-noresampblur,添加在命令的结束位置,下采样前就不会针对原图像进行平滑了。下采样过程中对于图像质量要求较高,如果下采样过程中参照的像素点包含很大的噪声的话,的确会造成下采样过后图像的原本信息遭到损失,所以是否进行模糊处理需要根据实际情况决定。

fslcreatehd
Usage: fslcreatehd <xsize> <ysize> <zsize> <tsize> <xvoxsize> <yvoxsize> <zvoxsize> <tr> <xorigin> <yorigin> <zorigin> <datatype> <filename>
       fslcreatehd <nifti_xml_file> <filename>
  Datatype values: 2=char, 4=short, 8=int, 16=float, 64=double
  In the first form, a radiological image will be created, with the origin input as a voxel co-ordinate.
  If the output file already exists, its data ( but not geometric information ) will be copied if it has
  a matching number of elements.
  In the second form, an XML-ish form of nifti header is read (as output by fslhd -x)
  Note that stdin is used if '-' is used in place of a filename

e.g.
fslcreatehd 120 160 120 3 2 2 2 0 0 0 0 16 test_2mm

使用实例中的命令,可以得到一个大小为120160120,volume为3的2mm分辨率的参考图像,数据格式为float,文件名称为 test_2mm,图像内所有值都为0

这里tr,一般设置为0,是volumes之间的时间间隔

x/y/z origin一般设置为0 0 0

fslinfo test_2mm.nii.gz
fsledithd test_2mm.nii.gz

使用fslinfo可以查看图像的信息,包括体素大小,体素数量

使用fsledithd可以修改图像header文件

现在生成一个对角矩阵用于变换图像,因为不需要做空间上旋转与扭曲,所以生成一个eye矩阵就可以,表示不做配准操作

touch eye.mat #生成一个mat文件叫eye
#文件里面内容
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

下面正式进行降采样

# flirt command downsample the image 
flirt -in high_res.nii.gz -ref test_2mm.nii.gz -applyxfm -init eye.mat -out low_res.nii.gz -interp trilinear

# flirt command upsample the image
flirt -in low_res.nii.gz -ref high_res.nii.gz -applyxfm -init eye.mat -out resample_image.nii.gz -interp spline

进行采样的插值函数可以选择:trilinear, nearestneighbour, sinc, spline

插值函数的具体选择,请根据具体情况进行选择

这样得到的resample_image可以认为是具有了低分辨率但是图像矩阵的大小与原来相同

根据flirt函数的参考文档,似乎还有其他的方法可以实现相似的操作,欢迎交流

参考文档

https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Fslutils

https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FLIRT/FAQ#Can_I_register_to_an_image_but_use_higher.2Flower_resolution_.28voxel_size.29.3F

https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FLIRT/UserGuide#applyxfm4d

https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=fsl;4baa23b3.0709

https://andysbrainbook.readthedocs.io/en/latest/FrequentlyAskedQuestions/FrequentlyAskedQuestions.html

你可能感兴趣的:(图像,FSL,其他)