-
Notifications
You must be signed in to change notification settings - Fork 0
/
minc-diff-labels-visualize.sh
executable file
·80 lines (65 loc) · 2.89 KB
/
minc-diff-labels-visualize.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
#!/bin/bash
#Generate auto-scaled MaGeT QC image
#TODO
#-option for label on-off slices
#-option for number of slices
#-option for image size
#-clobber check
set -euo pipefail
#set -x
image=$1
labels=$2
output=$3
tmpdir=$(mktemp -d)
patchlabels=$(mincinfo -varvalues time ${labels})
i=0
for label in ${patchlabels}; do
echo "mincreshape -valid_range -1 1 ${labels} ${tmpdir}/${label}_patch.mnc -dimrange time=${i} -signed -byte && \
minclookup -byte -unsigned -labels -discrete -lut_string \"-1 2; 1 1\" ${tmpdir}/${label}_patch.mnc ${tmpdir}/${label}_patch_fix.mnc"
# Generate an empty file if not present in existing label set so we can patch it
((i++)) || true
done | parallel -j $(nproc)
# Generate a bounding box
mincmath -or ${tmpdir}/*_patch_fix.mnc ${tmpdir}/label_flatten.mnc
mincresample -unsigned -int -keep -near -labels $(mincbbox -mincresample ${tmpdir}/label_flatten.mnc | grep -v Reading) \
${tmpdir}/label_flatten.mnc ${tmpdir}/label-crop.mnc
minccalc -expression "1" ${tmpdir}/label-crop.mnc ${tmpdir}/bounding.mnc
# Labelled layers
for label in ${patchlabels}; do
echo """
create_verify_image -transpose -range_floor 0 ${tmpdir}/$(basename ${image} .mnc)_t_${label}.mpc \
-width 3840 -height 1600 -autocols 10 -autocol_planes t \
-bounding_volume ${tmpdir}/bounding.mnc \
-row ${image} color:gray \
volume_overlay:${tmpdir}/${label}_patch_fix.mnc:0.7:2:blue,1:red \
title:\"Label ${label}\" \
-norepeattitle
create_verify_image -transpose -range_floor 0 ${tmpdir}/$(basename ${image} .mnc)_s_${label}.mpc \
-width 3840 -height 1600 -autocols 10 -autocol_planes s \
-bounding_volume ${tmpdir}/bounding.mnc \
-row ${image} color:gray \
volume_overlay:${tmpdir}/${label}_patch_fix.mnc:0.7:2:blue,1:red \
title:\"Label ${label}\" \
-norepeattitle
create_verify_image -transpose -range_floor 0 ${tmpdir}/$(basename ${image} .mnc)_c_${label}.mpc \
-width 3840 -height 1600 -autocols 10 -autocol_planes c \
-bounding_volume ${tmpdir}/bounding.mnc \
-row ${image} color:gray \
volume_overlay:${tmpdir}/${label}_patch_fix.mnc:0.7:2:blue,1:red \
title:\"Label ${label}\" \
-norepeattitle
"""
done | parallel -j $(nproc)
convert -background black -strip -interlace Plane -sampling-factor 4:2:0 -quality "95%" \
+append -trim \
$(for label in ${patchlabels}; do echo ${tmpdir}/$(basename ${image} .mnc)_t_${label}.mpc; done) \
${output}_t.jpg
convert -background black -strip -interlace Plane -sampling-factor 4:2:0 -quality "95%" \
+append -trim \
$(for label in ${patchlabels}; do echo ${tmpdir}/$(basename ${image} .mnc)_s_${label}.mpc; done) \
${output}_s.jpg
convert -background black -strip -interlace Plane -sampling-factor 4:2:0 -quality "95%" \
+append -trim \
$(for label in ${patchlabels}; do echo ${tmpdir}/$(basename ${image} .mnc)_c_${label}.mpc; done) \
${output}_c.jpg
rm -rf ${tmpdir}