Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phantom_distortion_measure_v2 DIED #166

Open
emilljungberg opened this issue Nov 15, 2023 · 1 comment
Open

phantom_distortion_measure_v2 DIED #166

emilljungberg opened this issue Nov 15, 2023 · 1 comment

Comments

@emilljungberg
Copy link

Hi,

I'm trying to use the phantom_distortion_measure_v2.pl tool to map geometric distortions in phantom scans, but I'm unfortunately running into some problems. I'm running minc on a Mac with the M1 chip. Initially I had some trouble with the installation so I installed everything in a docker container running ubuntu where it seems to work fine. However, I face the same error in the docker as I did when I tried to run it natively on my Mac. Below is the output when I try to run it where I have two near identical scans as a first simple test, both using the same mask. The last output which says "DIED" doesn't give me very much help to figure out what the issue is. Do you have any suggestions for what I can do to investigate this further or have you seen anything like this before?

>> /opt/minc/1.9.18/bin/phantom_distortion_measure_v2.pl run2.mnc mask.mnc out.par out.xfm out.csv --model run1.mnc --mask mask.mnc  --debug -v

cp run2.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/run2.mnc
bestlinreg_s2 run1.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/run2.mnc -source_mask mask.mnc -target_mask mask.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/align_run2.mnc.xfm -lsq6
-+-------------------------[0]-------------------------
 | steps:          8 8 8
 | blur_fwhm:      16
 | simplex:        32
 | source:         /tmp/bestlinreg_s2-etUfKTME/s_run1_16_blur.mnc
 | target:         /tmp/bestlinreg_s2-etUfKTME/t_run2_16_blur.mnc
 | xfm:            /tmp/bestlinreg_s2-etUfKTME/s_run1_0.xfm
-+-----------------------------------------------------

mincblur -clobber -no_apodize -fwhm 16 run1.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_16
Making byte volume...
mincblur -clobber -no_apodize -fwhm 16 /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/run2.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_16
Making byte volume...
minctracc -clobber -lsq6 -step 8 8 8 -simplex 32 -tol 0.01 -est_translations -source_mask mask.mnc -model_mask mask.mnc -xcorr /tmp/bestlinreg_s2-etUfKTME/s_run1_16_blur.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_16_blur.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_0.xfm
COG of v1: -88.492462 -103.898712 -93.837944
COG of v2: -88.543167 -103.861328 -93.582901
   [trans] = -0.050705 0.037384 0.255043
Only center & trans required, now returning from init_transformation
Initial objective function val = 0.00004083
Final objective function value = 0.00003528
-+-------------------------[1]-------------------------
 | steps:          4 4 4
 | blur_fwhm:      8
 | simplex:        16
 | source:         /tmp/bestlinreg_s2-etUfKTME/s_run1_8_blur.mnc
 | target:         /tmp/bestlinreg_s2-etUfKTME/t_run2_8_blur.mnc
 | xfm:            /tmp/bestlinreg_s2-etUfKTME/s_run1_1.xfm
-+-----------------------------------------------------

mincblur -clobber -no_apodize -fwhm 8 run1.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_8
Making byte volume...
mincblur -clobber -no_apodize -fwhm 8 /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/run2.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_8
Making byte volume...
minctracc -clobber -lsq6 -step 4 4 4 -simplex 16 -tol 0.004 -transformation /tmp/bestlinreg_s2-etUfKTME/s_run1_0.xfm -source_mask mask.mnc -model_mask mask.mnc -xcorr /tmp/bestlinreg_s2-etUfKTME/s_run1_8_blur.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_8_blur.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_1.xfm
Initial objective function val = 0.00010725
Final objective function value = 0.00009617
-+-------------------------[2]-------------------------
 | steps:          4 4 4
 | blur_fwhm:      4
 | simplex:        8
 | source:         /tmp/bestlinreg_s2-etUfKTME/s_run1_4_blur.mnc
 | target:         /tmp/bestlinreg_s2-etUfKTME/t_run2_4_blur.mnc
 | xfm:            /tmp/bestlinreg_s2-etUfKTME/s_run1_2.xfm
-+-----------------------------------------------------

mincblur -clobber -no_apodize -fwhm 4 run1.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_4
Making byte volume...
mincblur -clobber -no_apodize -fwhm 4 /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/run2.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_4
Making byte volume...
minctracc -clobber -lsq6 -step 4 4 4 -simplex 8 -tol 0.004 -transformation /tmp/bestlinreg_s2-etUfKTME/s_run1_1.xfm -source_mask mask.mnc -model_mask mask.mnc -xcorr /tmp/bestlinreg_s2-etUfKTME/s_run1_4_blur.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_4_blur.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_2.xfm
Initial objective function val = 0.00045241
Final objective function value = 0.00045241
-+-------------------------[3]-------------------------
 | steps:          4 4 4
 | blur_fwhm:      8
 | simplex:        4
 | source:         /tmp/bestlinreg_s2-etUfKTME/s_run1_8_dxyz.mnc
 | target:         /tmp/bestlinreg_s2-etUfKTME/t_run2_8_dxyz.mnc
 | xfm:            /tmp/bestlinreg_s2-etUfKTME/s_run1_3.xfm
-+-----------------------------------------------------

mincblur -clobber -no_apodize -fwhm 8 -gradient run1.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_8
Making byte volume...
Transforming slices:........................................Done
Making byte volume dx...Making byte volume dy...Making byte volume dz...mincblur -clobber -no_apodize -fwhm 8 -gradient /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/run2.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_8
Making byte volume...
Transforming slices:........................................Done
Making byte volume dx...Making byte volume dy...Making byte volume dz...minctracc -clobber -lsq6 -step 4 4 4 -simplex 4 -tol 0.004 -transformation /tmp/bestlinreg_s2-etUfKTME/s_run1_2.xfm -source_mask mask.mnc -model_mask mask.mnc -xcorr /tmp/bestlinreg_s2-etUfKTME/s_run1_8_dxyz.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_8_dxyz.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_3.xfm
Initial objective function val = 0.00048976
Final objective function value = 0.00048693
-+-------------------------[4]-------------------------
 | steps:          4 4 4
 | blur_fwhm:      4
 | simplex:        2
 | source:         /tmp/bestlinreg_s2-etUfKTME/s_run1_4_dxyz.mnc
 | target:         /tmp/bestlinreg_s2-etUfKTME/t_run2_4_dxyz.mnc
 | xfm:            /tmp/bestlinreg_s2-etUfKTME/s_run1_4.xfm
-+-----------------------------------------------------

mincblur -clobber -no_apodize -fwhm 4 -gradient run1.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_4
Making byte volume...
Transforming slices:........................................Done
Making byte volume dx...Making byte volume dy...Making byte volume dz...mincblur -clobber -no_apodize -fwhm 4 -gradient /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/run2.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_4
Making byte volume...
Transforming slices:........................................Done
Making byte volume dx...Making byte volume dy...Making byte volume dz...minctracc -clobber -lsq6 -step 4 4 4 -simplex 2 -tol 0.004 -transformation /tmp/bestlinreg_s2-etUfKTME/s_run1_3.xfm -source_mask mask.mnc -model_mask mask.mnc -xcorr /tmp/bestlinreg_s2-etUfKTME/s_run1_4_dxyz.mnc /tmp/bestlinreg_s2-etUfKTME/t_run2_4_dxyz.mnc /tmp/bestlinreg_s2-etUfKTME/s_run1_4.xfm
Initial objective function val = 0.00358132
Final objective function value = 0.00356813
mv -f /tmp/bestlinreg_s2-etUfKTME/s_run1_4.xfm /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/align_run2.mnc.xfm
mincresample run1.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_run2.mnc -like /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/run2.mnc -transform /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/align_run2.mnc.xfm
Transforming slices:........................................Done
itk_morph --threshold 50 --exp D[6] E[2] /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_run2.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask_run2.mnc
Dilate 6
Erode 2
mincresample mask.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask2_run2.mnc -like /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask_run2.mnc -transform /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/align_run2.mnc.xfm
Transforming slices:........................................Done
minccalc -express A[0]>0.5&&A[1]>0.5?1:0 -byte /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask_run2.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask2_run2.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask_run2.mnc
minccalc: /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask_run2.mnc exists, use -clobber to overwrite

DIED: minccalc -express A[0]>0.5&&A[1]>0.5?1:0 -byte /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask_run2.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask2_run2.mnc /tmp/phantom_distortion_measure_v2.pl-35cUY1V5/ideal_mask_run2.mnc
@vfonov
Copy link
Member

vfonov commented Nov 15, 2023

Hello,
sorry for the lack of documentation, you are the first to try to use these scripts in the last 10 years.
Briefly, the phantom scans need to be preprocessed first, and then phantom_distortion_measure_v2.pl script also needs a few extra arguments to function properly.

It should be roughly like following, you need to provide also phantom_model.mnc - "ideal" phantom, phantom_model_mask.mnc - ideal phantom mask, phantom_bricks_map.mnc - map of lego bricks inside of the ideal phantom.

# preprocess scans separately
lego_core_extract.pl raw_scan1.mnc preproc_scan1.mnc preproc_scan1_mask.mnc --grayscale --nuc --denoise
lego_core_extract.pl raw_scan2.mnc preproc_scan2.mnc preproc_scan2_mask.mnc --grayscale --nuc --denoise
....
lego_core_extract.pl raw_scanN.mnc preproc_scanN.mnc preproc_scanN_mask.mnc --grayscale --nuc --denoise

# estimate distortion field with mean square approximation using all scans
phantom_distortion_measure_v2.pl \
           --model phantom_model.mnc  --mask phantom_model_mask.mnc  --bricks phantom_bricks_map.mnc \ 
           --work_dir (temprorary work dir) \
            --order 5 --elastix \
          preproc_scan1.mnc preproc_scan1_mask.mnc \
          preproc_scan2.mnc preproc_scan2_mask.mnc \
          .... \
          preproc_scanN.mnc preproc_scanN_mask.mnc \
         output_par.txt output_distcorr.xfm output_stats.csv --out-roi output_roi_mask.mnc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants