Skip to content

Commit

Permalink
Merge pull request #2 from hcmh/master
Browse files Browse the repository at this point in the history
revision
  • Loading branch information
hcmh committed Mar 5, 2019
2 parents 6c32186 + 7ef1cfb commit 2a0ce4d
Show file tree
Hide file tree
Showing 52 changed files with 459 additions and 66 deletions.
46 changes: 46 additions & 0 deletions 04_newton_noise/brain/1_create_figure.sh
Expand Up @@ -17,6 +17,41 @@ TMP=tmp
mkdir ${TMP} || true
cd $TMP



#add arrow
arrow_head="l 0,0 +200,+500 -200,+500 +1500,-500 z"

convert -size 1500x1000 xc:None \
-draw "stroke white fill white scale 1,1 rotate 0
path 'M 000,000 $arrow_head' " \
arrow.png

declare -A uARROWS
uARROWS["22_0.05"]="+218+219 +541+641"
uARROWS["25_0.01"]="+240+240 +224+286 +175+583"
uARROWS["25_0.025"]="+230+195 +180+233 +141+390 +100+605"
uARROWS["25_0.05"]="+241+125 +190+195 +130+295 +100+347 +141+588 +130+673 +460+823"


#add offsets
offsetx=54
offsety=59
declare -A ARROWS
for i in "${!uARROWS[@]}"
do
arrow=""
for uarrow in ${uARROWS[$i]}
do
X=$(echo $uarrow | cut -f2 -d"+")
Y=$(echo $uarrow | cut -f3 -d"+")
(( X = X - offsetx ))
(( Y = Y - offsety ))
arrow="$arrow +$X+$Y"
done
ARROWS[$i]="$arrow"
done

scale_and_text()
{
IF="$1"
Expand All @@ -40,6 +75,17 @@ do
else
cp ../r_mm_${N}_${NOISE}.png ${N}_${NOISE}.png
fi

arg="${N}_${NOISE}"
arrows=${ARROWS[$arg]+"${ARROWS[$arg]}"}
if [ ! -z "$arrows" ]
then
for arrow in ${arrows[@]}
do
convert ${N}_${NOISE}.png \( ./arrow.png -scale 04\% -geometry "$arrow" -background None -rotate 50 \) -composite ${N}_${NOISE}.png
done
fi

done

convert -interword-spacing 1 -rotate -90 -density ${DENSITY} -pointsize ${FONTSIZE} -font ${FONT} caption:"${NSTRING}" -gravity Center ../r_mm_${NEWTONS[0]}_${NOISE}.png +append -gravity east -splice x0 N_tmp.png
Expand Down
1 change: 0 additions & 1 deletion 04_newton_noise/brain/doit.sh
Expand Up @@ -2,7 +2,6 @@
set -euo pipefail
set -B

# ENLIVE reco first:
# param is output directory
./0_reco_enlive.sh reco_ENLIVE

Expand Down
Expand Up @@ -6,6 +6,7 @@ source head/opts.sh
DIR=reco
SL1=phantom/${DIR}/${DIR}.png
SL2=head/${DIR}/${DIR}.png
SL3=heart/${DIR}/${DIR}.png

Y=$(identify -format "%[fx:h]" phantom/${DIR}/r_sm.png)
DENSITY=$( echo 'scale=5; 72/192*'$Y | bc)
Expand All @@ -29,22 +30,27 @@ scale_and_text()
#the space after a and b is a unicode U+2009 THIN SPACE
scale_and_text ../${SL1} "a " 1.png
scale_and_text ../${SL2} "b " 2.png
W=$(identify -format "%[fx:w]" ../${SL2})
convert -geometry ${W}x ../${SL3} tmp3.png
scale_and_text tmp3.png "c " 3.png

montage -background white -alpha remove 1.png 2.png -tile 1x2 \

montage -background white -alpha remove 1.png 2.png 3.png -tile 1x3 \
-geometry "1x1+0+${SPACING}<" -border 0 tmp.png

H=$(identify -format "%[fx:h]" tmp.png)
H2=$(echo "$H/2" | bc)

convert ../../MYGBM_colorbar.png -geometry x${H} cb_tmp.png
convert ../../MYGBM_colorbar.png -geometry x${H2} cb_tmp.png

convert tmp.png cb_tmp.png +append -layers mosaic tmp2.png
convert tmp.png cb_tmp.png -gravity east +append -layers mosaic tmp2.png


#remove whitespace around final image:
convert tmp2.png -density ${DENSITY} -units PixelsPerInch -crop +0+${SPACING} +repage -crop -0-${SPACING} +repage ../bh_headvphantom.png
convert tmp2.png -density ${DENSITY} -units PixelsPerInch -crop +0+${SPACING} +repage -crop -0-${SPACING} +repage ../bh_phan_head_heart.png


cd ..
rm -r ${TMP}

cp bh_headvphantom.png ../output/07_fig_blackholes.png
cp bh_phan_head_heart.png ../output/07_fig_blackholes.png
@@ -1,3 +1,3 @@
reco_*/
reco/
data/*
!data/unders.*
Expand Up @@ -4,26 +4,36 @@ source opts.sh
set -euo pipefail
set -B

#if false; then
# # generate undersampled data
# # T6439, sl2, 21-25
# RAW=/home/ague/archive/2016/2016-08-30_Sequence_bSSFP/T006439/T006439_raw.coo
# $BART extract 11 2 2 $RAW data/tmp
# $BART extract 10 21 25 data/tmp{,2}
# $BART transpose 2 10 data/tmp{2,}
# $BART circshift 2 4 data/tmp{,2}
# $BART reshape 6 $NSPK 1 data/tmp{2,}
# $BART transpose 1 2 data/tmp{,2}
# $BART transpose 0 1 data/tmp2 data/unders
#fi
if false; then
# generate undersampled data

# TT10740, sl9, 15-20
DAT=/home/ague/archive/volunteers/2018-09-07_MRT5_ADVM_0004/2018-09-07_SA_BlackHoles/meas_MID00268_FID25607_mpi_rfl40_33ms_SA_mit_VH_20_3.dat
RAW=data/raw_T10740
$BART twixread -A $DAT $RAW
NSPK=$(echo "$NSSPK"*"$NTURN" | bc)
$BART slice 13 07 $RAW data/tmp
$BART extract 10 80 85 data/tmp{,2}
$BART transpose 2 10 data/tmp{2,}
$BART circshift 2 3 data/tmp{,2}

$BART reshape 6 $NSPK 1 data/tmp{2,}
$BART transpose 1 2 data/tmp{,2}
$BART transpose 0 1 data/tmp2 data/unders
fi

NSSPK=15
NTURN=5
NSPK=$(echo "$NSSPK"*"$NTURN" | bc)
NC=$($BART show -d3 data/unders)

$BART traj -x$NSMPL -y$NSPK -t5 -D data/traj_uncorr

# gradient delays
GD=$($BART estdelay data/traj_uncorr data/unders)

$BART traj -x$NSMPL -y$NSPK -t5 -D -q${GD} data/tmp
$BART reshape 12 13 5 data/tmp{,2}
$BART reshape 12 $NSSPK $NTURN data/tmp{,2}
$BART circshift 3 3 data/tmp{2,}
$BART reshape 12 $NSPK 1 data/tmp data/traj

Expand All @@ -35,9 +45,9 @@ $BART scale $OG data/traj data/traj_scaled
SCALE=$(echo "scale=5;1./"$NSPK | bc -l)
$BART nufft -d$S:$S:1 -a data/traj_scaled data/unders data/tmp_grid > /dev/null
$BART fft -u 7 data/tmp_grid data/tmp
$BART scale $SCALE data/tmp data/grid

$BART scale 1. data/tmp data/grid

#PSF
$BART ones 3 1 $NSMPL $NSPK data/tmp_o
$BART nufft -d$S:$S:1 -a data/traj_scaled data/tmp_o data/tmp > /dev/null
$BART fft -u 7 data/tmp{,2}
Expand Down
Expand Up @@ -13,13 +13,14 @@ out=$1
DEBUG=4

#resize to:
CROP=$(echo "scale=0;"$NSMPL"*"$OG"/3" | bc -l)
CROP=$(echo "scale=0;"$NSMPL"/2*1.1" | bc -l)
for ((m=1; m<=$COMP_MAPS; m++))
do
$BART nlinv -d$DEBUG -m$m $NLINV_OPTS $DATA $out/tmp_${m} >$out/log_r_mm_${m} 2>&1
$BART resize -c 0 $CROP 1 $CROP $out/tmp_${m} $out/r_mm_${m}
$BART rss 4096 $out/r_mm_${m} $out/tmp_rss_${m}
$CFL2PNG $CFLCOMMON $out/tmp_rss_${m} $out/r_mm_${m}.png
$CFL2PNG -C Y $CFLCOMMON $out/r_mm_${m} $out/r_mm_${m}_phase.png

if [ "$m" -eq "$COMP_MAPS" ]
then
Expand Down
47 changes: 47 additions & 0 deletions 07_phase_singularities/heart/2_create_figure.sh
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail

source ../../FONT.sh
source opts.sh

#first argument is both dir name and output name
DIR="$1"
cd ${DIR}

Y=$(identify -format "%[fx:h]" ./r_mm_1.png)
#set density. 72 means 1pt is 1 pxl
DENSITY=$( echo 'scale=5; 72/192*'$Y | bc)
FONTSIZE=$( echo 'scale=0; 192/6' | bc)
SPACING=$( echo 'scale=0; '${Y}'/48' | bc)
STRW=3

TMP=tmp
mkdir ${TMP} || true
cd $TMP

scale_and_text()
{
IF="$1"
T="$2"
OF="$3"
convert ${IF} -stroke red -strokewidth ${STRW} -fill none -draw "translate ${circle_x},${circle_y} circle 0,0 ${circle_r},0" tmp.png
convert tmp.png -density ${DENSITY} -pointsize ${FONTSIZE} -font ${FONT} label:"${T}" -gravity Center -append ${OF}
rm tmp.png

}


scale_and_text "../r_mm_1.png" "1 map" 1m.png
scale_and_text "../r_mm_2.png" "2 maps" 2m.png
scale_and_text "../r_mm_1_phase.png" "1 map phase" phase.png

scale_and_text ../r_mmu_2_map_0000.png "map #1" m0.png
scale_and_text ../r_mmu_2_map_0001.png "map #2" m1.png
montage -background white -alpha remove phase.png 1m.png 2m.png m0.png m1.png -tile 5x1 -geometry "1x1+${SPACING}+0<" tmp.png

#remove whitespace around final image:
convert tmp.png -density ${DENSITY} -units PixelsPerInch -crop +${SPACING}+0 +repage -crop -${SPACING}-0 +repage ../${DIR}.png

cd ..
rm -r ${TMP}
cd ..
Binary file added 07_phase_singularities/heart/data/unders.cfl
Binary file not shown.
@@ -1,8 +1,8 @@
# Dimensions
1 320 65 30 1 1 1 1 1 1 1 1 1 1 1 1
1 320 75 30 1 1 1 1 1 1 1 1 1 1 1 1
# Command
transpose 0 1 data/tmp2 data/unders
# Files
>data/unders <data/tmp2
# Creator
BART v0.4.01-62-gba56e21
BART v0.4.03
8 changes: 8 additions & 0 deletions 07_phase_singularities/heart/doit.sh
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail

./0_prep.sh

./1_reco_enlive.sh reco

./2_create_figure.sh reco
@@ -1,16 +1,20 @@
ZOOM=3
DATA=data/grid
REF=data/ref
WMAX=0.4
WMAX=0.3
CFLCOMMON="-z$ZOOM -u$WMAX -FZ -x0 -y1"

NEWTON=11
REDU=2
NEWTON=17
REDU=1.5

NLINV_OPTS="-a240 -b40 -i${NEWTON} -R${REDU} -S -f0.5 -pdata/psf"
MAPS=2
COMP_MAPS=2

NSMPL=320
NSPK=65
OG=1.5


circle_r=$(( 12 * $ZOOM ))
circle_x=$(( ( 176 - 163 ) * $ZOOM ))
circle_y=$(( ( 176 - 45 ) * $ZOOM ))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions 08_09_lowrank/knee/.gitignore
@@ -0,0 +1,3 @@
reco*/
data/*
!data/single_slice.*
26 changes: 26 additions & 0 deletions 08_09_lowrank/knee/0_prep.sh
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail

source ../../BART.sh

if false;
then
cd data
wget http://old.mridata.org/knees/fully_sampled/p3/e1/s1/P3.zip
unzip P3.zip
cd ..

#extract single slice
$BART fft -u -i 1 data/kspace data/tmp_fft
$BART slice 0 160 data/tmp_fft data/single_slice
fi

$BART rss 8 data/single_slice data/tmp_rss
$BART threshold -H 21 data/tmp_rss data/tmp_pat
$BART pattern data/tmp_pat data/pat
$BART fmac data/pat data/single_slice data/tmp_full
#scale maximum to about 1
$BART scale 1e-8 data/tmp_full data/full


rm data/tmp_*
40 changes: 40 additions & 0 deletions 08_09_lowrank/knee/1_gen_unders.sh
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail

source ../../BART.sh

US=$1

SEED=20869

# VD-PD for total undersampling of $US:
$BART poisson -Y320 -Z256 -y$US -z$US -v -V05 -s$SEED data/tmp_pat_${US} > /dev/null
$BART pattern data/full data/s_${US}
$BART fmac data/tmp_pat_${US} data/s_${US} data/pat_${US}
rm data/tmp_pat_${US}.*

#calculate undersampling
$BART fmac -s 65535 data/s_${US} data/s_${US} data/ns_${US}
$BART fmac -s 65535 data/pat_${US} data/pat_${US} data/npat_${US}
ALL=$($BART show -f "%+f%+fi" data/ns_${US} | cut -f1 -d"." | cut -f2 -d"+")
PAT=$($BART show -f "%+f%+fi" data/npat_${US} | cut -f1 -d"." | cut -f2 -d"+")
rm data/ns_${US}.* data/npat_${US}.* data/s_${US}.*

UNDERS=$(echo "scale=1;"$ALL"/"$PAT | bc -l)
echo $UNDERS > data/undersampling_factor_${US}.txt

source opts.sh
US_NAME=$(GET_US $US)

mv data/pat_${US}.cfl data/pat_${US_NAME}.cfl
mv data/pat_${US}.hdr data/pat_${US_NAME}.hdr
$BART fmac data/full data/pat_${US_NAME} data/unders_${US_NAME}

# rss reco:
mkdir -p reco_zerofill
$BART fft -u -i 7 data/unders_${US_NAME} data/tmp_${US_NAME}
$BART rss 8 data/tmp_${US_NAME} reco_zerofill/zf_${US_NAME}
$CFL2PNG $CFLCOMMON reco_zerofill/zf_${US_NAME}{,.png}

rm data/tmp_${US_NAME}.*

27 changes: 27 additions & 0 deletions 08_09_lowrank/knee/2_reco_enlive.sh
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
source ../../BART.sh
source opts.sh

set -euo pipefail
# brace expand
set -B

out=$1
US=$(GET_US $2)

DEBUG=4
MAPS=2

export OMP_NUM_THREADS=1

# regular
{ time $BART nlinv -d$DEBUG -m$MAPS -U $NLINV_OPTS ${DATA}_${US} $out/r_mmu_${US}; } \
>$out/log_r_mmu_${US} 2>$out/timelog_r_mmu_${US}
$CFL2PNG $CFLCOMMON $out/r_mmu_${US}{,}

$BART nlinv -d$DEBUG -m$MAPS $NLINV_OPTS ${DATA}_${US} $out/r_mm_${US} >$out/log_r_mm_${US}
$CFL2PNG $CFLCOMMON $out/r_mm_${US}{,}

$BART nlinv -d$DEBUG -m1 $NLINV_OPTS ${DATA}_${US} $out/{r,s}_sm_${US} >$out/log_r_sm_${US}
$CFL2PNG $CFLCOMMON $out/r_sm_${US}{,}
$CFL2PNG -C Y $CFLCOMMON $out/r_sm_${US} $out/r_sm_phase_${US}.png

0 comments on commit 2a0ce4d

Please sign in to comment.