Diff of /demo/mas_demo.sh [000000] .. [a6edca]

Switch to unified view

a b/demo/mas_demo.sh
1
#!/bin/bash
2
3
#########################################
4
# Demonstrate the comman usage of the
5
# Multi-Atlas Segmentation (MAS) pipeline
6
#########################################
7
8
9
# Add niftk installation location to system paths: `PATH` and `LD_LIBRARY_PATH`.
10
# This will only work if user followed the installation instruction, and installed packages in the recommended location.
11
# If you installed the packages in other locations, please change the variable `$HOME` to your own installed locations.
12
13
# Option 1: if user installed the default niftk package
14
export PATH=${PATH}:"$HOME/niftk-18.5.4/bin"
15
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"$HOME/niftk-18.5.4/bin"
16
17
# option 2: if use choose to compile the niftyreg/niftyseg from the source code.
18
export PATH=${PATH}:"$HOME/nifty_reg/bin"
19
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}/"$HOME/nifty_reg/lib"
20
export PATH=${PATH}:"$HOME/nifty_seg/bin"
21
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:"$HOME/nifty_seg/lib"
22
23
####################################
24
######## prepare demo data #########
25
####################################
26
27
# (Optional) create demo directory within the current folder (preferrably an empty folder)
28
mkdir -p ./demo
29
cd ./demo
30
31
# Download the "in_vivo" atlas from: https://github.com/dancebean/mouse-brain-atlas
32
mkdir -p Atlas
33
cd Atlas
34
svn export https://github.com/dancebean/mouse-brain-atlas/trunk/FVB_NCrl/in_vivo FVB_NCrl_in_vivo
35
# only use three atlas for fast processing and demonstration purpose
36
cat FVB_NCrl_in_vivo/template_list.cfg | head -n 3 > FVB_NCrl_in_vivo/template_list_demo.cfg
37
cd ..
38
39
# create input directory, file, and target list
40
mkdir -p ./input
41
cd ./input
42
target_id="A0"
43
svn export https://github.com/dancebean/mouse-brain-atlas/trunk/NeAt/in_vivo/template/$target_id.nii.gz
44
echo $target_id > targetlist.txt
45
cd ..
46
47
# create targetlist (only 1 file)
48
ls ./input | head -n 1 | cut -d. -f1 > targetlist.txt
49
50
# create output directory
51
mkdir -p ./output
52
53
54
####################################
55
######## start demo script #########
56
####################################
57
58
# Download the main script if not yet done
59
svn export --force https://github.com/dancebean/multi-atlas-segmentation/trunk/MASHelperFunctions.sh
60
# (Optional) Download the sample parameter configuration file
61
svn export --force https://github.com/dancebean/multi-atlas-segmentation/trunk/parameters_samples/parameter_sample.sh
62
# You can edit the advanced parameters to fine-tune the algorithm
63
64
# source the main script (or use the location of your own copy)
65
source ./MASHelperFunctions.sh
66
# Alternatively, if you want to mute the listing of all the available functions, use:
67
# source ./MASHelperFunctions.sh > /dev/null 2>&1
68
69
# define parameters
70
atlas_name="FVB_NCrl_in_vivo"
71
atlas_dir="Atlas/$atlas_name"
72
target_dir="input"
73
result_dir="output"
74
target_id="A0"
75
target_list="input/targetlist.txt"
76
atlas_list=$atlas_dir/template_list_demo.cfg
77
exe_mode=local
78
parameter_cfg=./parameter_sample.sh
79
80
dil_voxel=1
81
raw_mask_dir=$result_dir/mask
82
dilate_mask_dir=$result_dir/mask_dilate_$dil_voxel
83
mask_suffix=".mask.$atlas_name"
84
85
86
####################################
87
#### Demo script ####
88
####################################
89
90
# 1. ~~~~~ brain extracting/masking ~~~~~~
91
mas_masking_batch -T $target_dir -t $target_list -A $atlas_dir -a $atlas_list -r $result_dir -e $exe_mode # -p $parameter_cfg
92
93
# 2. ~~~~~ brain mask dilation (not always necessary, check the quickcheck images to decide) ~~~~~
94
mas_mask_dilate_batch $target_list $raw_mask_dir $dilate_mask_dir $mask_suffix $dil_voxel $exe_mode  # -p $parameter_cfg
95
# generate quickcheck for dilated mask
96
mas_quickcheck $target_dir/$target_id $dilate_mask_dir/$target_id$mask_suffix $result_dir/quickcheck/ \
97
               $target_id$mask_suffix.d_$dil_voxel # -p $parameter_cfg
98
99
# 3. ~~~~~ bias field correction ~~~~~
100
# [Skipped] This is an important step before the parcellation. It is skipped in the demo as the images are already "bias-corrected" using the N4 algorithm
101
102
# 4. ~~~~~ parcellation ~~~~~
103
mas_parcellation_batch -T $target_dir -t $target_list -A $atlas_dir -a $atlas_list -r $result_dir \
104
                       -M $dilate_mask_dir -m $mask_suffix -e $exe_mode # -p $parameter_cfg
105
106
# # alternatively, if using non-dilated mask:
107
# mas_parcellation_batch -T $target_dir -t $target_list -A $atlas_dir -a $atlas_list -r $result_dir \
108
#                        -M raw_mask_dir -m $mask_suffix -e local # -p $parameter_cfg