首先根据ANTs官方文档下载ANTs,mac or linux下载教程,win10以上系统则需要先安装wsl,然后再根据官方文档下载ANTs
在配置过程中遇到任何问题一般都可以从现有博客中找到解决方案,如果在git clone的时候一直连接不上,可以选择把ANTs整个下载下来,放到对应目录下就行
现在主要讲如何用ANTs对颅脑MRI进行预处理,处理顺序依次为:N4偏置场校正—配准—去颅骨
N4偏置场校正:
ANTs提供了官方示例,具体每个参数是什么含义可以去官方文档查询,无脑使用的话就把对应图像路径换掉就行
N4BiasFieldCorrection -d 3 -i /path/to/input_image.nii.gz -o /path/to/output_corrected.nii.gz
实际应用过程中手动依次对单个序列图像处理不现实,写了个对应脚本
#!/bin/bash
# set -x
function read_dir_file(){
for FILE in $(ls $1)
do
if [ -d "${1}/${FILE}" ]
then
sub_dir="${1}/${FILE}"
read_dir_file $sub_dir
else
# echo "${1}/${FILE}"
local goal_t1="t1.nii"
local goal_t2="t2.nii"
local goal_ce="ce.nii"
local name=$FILE
# echo $FILE
if [ $name = $goal_t1 ]
then
t1="${1}/${name}"
echo "${t1} is being N4BiasFieldCorrected...."
N4BiasFieldCorrection -d 3 -i ${t1} -o ${1}/N4_t1.nii
elif [ $name = $goal_t2 ]
then
t2="${1}/${name}"
echo "${t2} is being N4BiasFieldCorrected...."
N4BiasFieldCorrection -d 3 -i ${t2} -o ${1}/N4_t2.nii
elif [ $name = $goal_ce ]
then
ce="${1}/${name}"
echo "${ce} is being N4BiasFieldCorrected...."
N4BiasFieldCorrection -d 3 -i ${ce} -o ${1}/N4_ce.nii
fi
fi
done
}
read_dir_file /mnt/e/path/to/mri
# set +x
图像配准:
如果其中某个序列勾画了ROI,则把其他序列配准到有ROI的序列
antsRegistrationSyNQuick.sh -d 3 -f target.nii -m ori.nii -o $prefix
$prefix 是你生成新文件的前缀,运行此命令后会生成两个重要的nii文件
prefix_warped.nii 是 ori.nii 朝 target.nii配准后的新文件,prefix_inversewarped.nii 是 target.nii 朝 ori.nii配准的新文件
批处理脚本
#!/bin/bash
# set -x
function read_dir_file(){
for FILE in $(ls $1)
do
if [ -d "${1}/${FILE}" ]
then
sub_dir="${1}/${FILE}"
read_dir_file $sub_dir
else
# echo "${1}/${FILE}"
local goal_t1="N4_t1.nii"
local goal_ce="N4_ce.nii"
local name=$FILE
local t2="${1}/N4_t2.nii"
# echo $FILE
if [ $name = $goal_t1 ]
then
t1="${1}/${name}"
# echo "${1}/${name} is being registered..."
bash /opt/ANTs/bin/antsRegistrationSyNQuick.sh -d 3 -f ${t2} -m ${t1} -o ${1}/t1_to_t2_
elif [ $name = $goal_ce ]
then
ce="${1}/${name}"
# echo "${1}/${name} is being registered..."
bash /opt/ANTs/bin/antsRegistrationSyNQuick.sh -d 3 -f ${t2} -m ${ce} -o ${1}/ce_to_t2_
fi
fi
done
}
read_dir_file /mnt/e/path/to/mri
# set +x
去颅骨:
先下载一个没有颅骨的模板数据,可以下载ANTs中的OASIS,里边是T1的相关数据
antsBrainExtraction.sh -d 3 -a ori.nii -e T_template0.nii.gz -m T_template0_BrainCerebellumProbabilityMask.nii.gz -o $prefix
批处理脚本
#!/bin/bash
# set -x
function read_dir_file(){
for FILE in $(ls $1)
do
if [ -d "${1}/${FILE}" ]
then
sub_dir="${1}/${FILE}"
read_dir_file $sub_dir
else
# echo "${1}/${FILE}"
local goal_t1="t1_to_t2_Warped.nii.gz"
local goal_ce="ce_to_t2_Warped.nii.gz"
local goal_t2="N4_t2.nii"
local name=$FILE
local templete="/mnt/e/path/to/AOSIS/T_template0.nii.gz"
local mask="/mnt/e/path/to/AOSIS/T_template0_BrainCerebellumProbabilityMask.nii.gz"
# echo $FILE
if [ $name = $goal_t1 ]
then
t1="${1}/${name}"
# echo "${t1} is being BrainExtracted...."
bash /opt/ANTs/bin/antsBrainExtraction.sh -d 3 -a ${t1} -e ${templete} -m ${mask} -o ${1}/t1_
elif [ $name = $goal_t2 ]
then
t2="${1}/${name}"
# echo "${t2} is being BrainExtracted...."
bash /opt/ANTs/bin/antsBrainExtraction.sh -d 3 -a ${t2} -e ${templete} -m ${mask} -o ${1}/t2_
elif [ $name = $goal_ce ]
then
ce="${1}/${name}"
# echo "${ce} is being BrainExtracted...."
bash /opt/ANTs/bin/antsBrainExtraction.sh -d 3 -a ${ce} -e ${templete} -m ${mask} -o ${1}/ce_
fi
fi
done
}
read_dir_file /mnt/e/path/to/mri
# set +x