-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBITE_MRI_to_US.sh
executable file
·81 lines (55 loc) · 3.31 KB
/
BITE_MRI_to_US.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
# Input arguments
case_num=${1-"01"}
image_folder=${2:-"bucket/BITE_group2_nii/${case_num}"}
us_image_uncompressed="US3DT.nii"
mri_image_uncompressed="MR.nii"
tag_file="bucket/BITE_group2_nii/BITE_group2_nii_tags/${case_num}/${case_num}_all.tag"
# Create directory to store the outputs
mkdir -p $image_folder/output/deeds
output_folder="$image_folder/output/deeds"
us_image="$output_folder/US3DT.nii.gz"
mri_image="$output_folder/MR.nii.gz"
# Compress images to match format expected by deedsBCV
gzip -fck $image_folder/$us_image_uncompressed > $us_image
gzip -fck $image_folder/$mri_image_uncompressed > $mri_image
# Resample images into a common reference frame and isotropic voxel size of 0.5x0.5x0.5 mm
c3d $us_image $mri_image -reslice-identity -resample-mm 0.5x0.5x0.5mm -o $output_folder/Case${case_num}-MRI_in_US.nii.gz
c3d $us_image -resample-mm 0.5x0.5x0.5mm -o $output_folder/Case${case_num}-US.nii.gz
# Generate 2 text files containing landmarks
python3 ./landmarks_split_txt.py --inputtag $tag_file --savetxt $output_folder/Case${case_num}_lm
# Generate landmark segmentations as a NIFTI file
c3d $output_folder/Case${case_num}-MRI_in_US.nii.gz -scale 0 -landmarks-to-spheres $output_folder/Case${case_num}_lm_mri.txt 1 -o $output_folder/Case${case_num}-MRI-landmarks.nii.gz
c3d $output_folder/Case${case_num}-US.nii.gz -scale 0 -landmarks-to-spheres $output_folder/Case${case_num}_lm_us.txt 1 -o $output_folder/Case${case_num}-US-landmarks.nii.gz
# Compute linear rigid pre-registration
./linearBCV -F $output_folder/Case${case_num}-US.nii.gz -M $output_folder/Case${case_num}-MRI_in_US.nii.gz -R 1 -O $output_folder/affine
# Generate a field of zero displacements necessary for applyBCV
python3 ./generate_zero_displacements.py $output_folder $output_folder/Case${case_num}-MRI_in_US.nii.gz
# Apply linear preregistration to landmarks
./applyBCV -M $output_folder/Case${case_num}-MRI-landmarks.nii.gz \
-O $output_folder/zero \
-D $output_folder/Case${case_num}-MRI-landmarks_linear.nii.gz \
-A $output_folder/affine_matrix.txt
# Apply linear preregistration to MRI
./applyBCV -M $output_folder/Case${case_num}-MRI_in_US.nii.gz \
-O $output_folder/zero \
-D $output_folder/Case${case_num}-MRI_in_US_linear.nii.gz \
-A $output_folder/affine_matrix.txt
# Perform non linear registration
./deedsBCV -F $output_folder/Case${case_num}-US.nii.gz \
-M $output_folder/Case${case_num}-MRI_in_US.nii.gz \
-O $output_folder/Case${case_num}-deeds \
-S $output_folder/Case${case_num}-MRI-landmarks.nii.gz \
-A $output_folder/affine_matrix.txt \
-a 0.45
# Extract US background (pixels with 0 intensity exactly)
c3d $output_folder/Case${case_num}-US.nii.gz -threshold 0 0 0 1 -o $output_folder/mask_US.nii.gz
# Remove background from MRI
c3d $output_folder/Case${case_num}-deeds_deformed.nii.gz $output_folder/mask_US.nii.gz -multiply -o $output_folder/clean_MRI.nii.gz
# Calculate initial mTRE
# python3 ./landmarks_centre_mass.py --inputnii $output_folder/Case${case_num}-US-landmarks.nii.gz --movingnii $output_folder/Case${case_num}-MRI-landmarks.nii.gz --savetxt $output_folder/Case${case_num}-results
# Calculate mTRE
python3 ./landmarks_centre_mass.py \
--inputnii $output_folder/Case${case_num}-US-landmarks.nii.gz \
--movingnii $output_folder/Case${case_num}-deeds_deformed_seg.nii.gz \
--savetxt $output_folder/Case${case_num}-results