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

rotational_minctracc .py has a numeric type comparison error when comparing world co-ordinates #45

Open
dorkylever opened this issue Sep 21, 2019 · 1 comment

Comments

@dorkylever
Copy link

Hi everyone,

I've being to trying to match some of our microCT scans of E15 embryos to the init_model available at http://www.mouseimaging.ca/technologies/mouse_atlas/mouse_embryo_atlas.html to ultimately ensure that rotational_minctracc.py does not fail when it is called in the MBM.py pipeline.

These CT scans were 512 DICOM images (512X512 pixels) that were converted to a MINC volume using dcm2mnc. I've displayed the mincinfo of one of these volumes below:

mincinfo 1908016_kat243_e6_fov20_20190816_110850_111039.mnc
file: 1908016_kat243_e6_fov20_20190816_110850_111039.mnc
image: unsigned short 0 to 65535
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 512 -0.04 10.24
yspace 512 0.04 -10.24
xspace 512 0.04 -10.24

I also have to do some image processing on these scans to remove a undesired background stage (stage_labelledis a label volume where I manually segmented the stage) but this has no effects on mincinfo.

mincmath -clobber -div 1908016_kat243_e6_fov20_20190816_110850_111039.mnc correct_stage.mnc stage_labelled.mnc
mincmath -clobber -const2 0 100000 -clamp stage_labelled.mnc 190816_kat243_e6_KaX.mnc
mincinfo 190816_kat243_e6_KaX.mnc
file: 190816_kat243_e6_KaX.mnc
image: unsigned short 0 to 65535
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 512 -0.04 10.24
yspace 512 0.04 -10.24
xspace 512 0.04 -10.24

In comparison, both the model and mask that I am trying to convert/match our CT-scans to has the following properties:

mincinfo final_model.mnc
file: final_model.mnc
image: signed__ short -32768 to 32767
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 602 0.027 -15.0564
yspace 405 0.027 -8.6925
xspace 347 0.027 -5.11522

To get these volumes to match I am running the folllowing commands:

#convert our scans to the right resolution/steps

autocrop -clobber -signed -step 0.027 0.027 0.027 1908016_kat243_e6_fov20_20190816_110850_111039.mnc test_autocrop.mnc
mincinfo test_autocrop.mnc
mincinfo test_autocrop.mnc
file: test_autocrop.mnc
image: signed__ short -32768 to 32767
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 759 0.027 -10.2
yspace 759 0.027 -10.24
xspace 759 0.027 -10.24

#our raw scans contain embryos in different orientations. As such I need to use #rotational_minctracc which needs a mask . As such, I have copied and enlarged the mask to be (759 X 759 X 759) and attempted to run rotational_minctracc.py to align two separately autocropped embryos (test_autocrop.mnc and test_autocrop_target.mnc) but it results in the follwing error.

mincreshape -clobber -start 0,0,0 count 759,759,759 image_mask.mnc enlarged_mask.mnc
mincinfo enlarged_mask.mnc test_autocrop.mnc test_autocrop_target.mnc
file: enlarged_mask.mnc
image: signed__ short -32768 to 32767
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 759 0.027 -15.0564
yspace 759 0.027 -8.6925
xspace 759 0.027 -5.11522

file: test_autocrop.mnc
image: unsigned short 0 to 65535
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 759 0.027 -10.2
yspace 759 0.027 -10.24
xspace 759 0.027 -10.24

file: test_autocrop_target.mnc
image: unsigned short 0 to 65535
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 759 0.027 -10.2
yspace 759 0.027 -10.24
xspace 759 0.027 -10.24

rotational_minctracc.py -m enlarged_mask.mnc test_autocrop.mnc test_autocrop_target.mnc test_minc_trans.fxm test_minc_vol.mnc
TMP: /tmp/
RANGE: 50 INTERVAL: 10
[autocrop] [minc@mincvm:/media/sf_vmshare/Kat_crp_mnc] [2019-09-21 04:25:31] /opt/minc/1.9.17/bin/mincresample test_autocrop.mnc //tmp//rot_17719/rot_0..mnc -start -10.24 -10.24 -10.2 -step 0.2 0.2 0.2 -nelements 103 103 103
Transforming slices:.......................................................................................................Done
[autocrop] [minc@mincvm:/media/sf_vmshare/Kat_crp_mnc] [2019-09-21 04:25:42] /opt/minc/1.9.17/bin/mincresample test_autocrop_target.mnc //tmp//rot_17719/rot_1.mnc -start -10.24 -10.24 -10.2 -step 0.2 0.2 0.2 -nelements 103 103 103
Transforming slices:.......................................................................................................Done
[autocrop] [minc@mincvm:/media/sf_vmshare/Kat_crp_mnc] [2019-09-21 04:25:53] /opt/minc/1.9.17/bin/mincresample enlarged_mask.mnc //tmp//rot_17719/rot_2.mnc -start -5.11522 -8.6925 -15.0564 -step 0.2 0.2 0.2 -nelements 103 103 103
Transforming slices:.......................................................................................................Done
Using positive peak threshold 7.2

Peaks found in the source image (Distance Transform):
[2.16 0.96 3.6 ]
[1.025 0.25 4.925]
[-2.84 -0.24 -4. ]
[ 0.24571429 -0.95428574 -2.7428572 ]
[-0.24 -1.04 -1.8 ]
[2.4933333 0.22666667 0.13333334]
Making byte volume...
Using positive peak threshold 3010.32

Peaks found in the source image (blurred image):
[ 0.56 1.76 -2.2 ]
[-1.24 1.16 -1. ]
[-1.44 1.76 -2.4 ]
[-0.84 -1.04 -1.2 ]
Using positive peak threshold 10.4

Peaks found in the target image (Distance Transform):
[-0.44 -1.44 4.8 ]
[-2.24 -1.24 4. ]
[-1.04 -1.84 5.4 ]
Making byte volume...
Using positive peak threshold 2963.95

Peaks found in the target image (blurrred image):
[ 0.36 2.16 -2.4 ]
[ 1.16 1.96 -0.8 ]
[ 0.16 -1.24 -2. ]
Transforming slices:.......................................................................................................Done
Files //tmp//rot_17719/rot_2.mnc and //tmp//rot_17719/rot_5.mnc have different start coordinates (zspace)
Traceback (most recent call last):
File "/opt/miniconda/bin/rotational_minctracc.py", line 4, in
import('pkg_resources').run_script('python-stuffs==0.1.24', 'rotational_minctracc.py')
File "/opt/miniconda/lib/python3.7/site-packages/pkg_resources/init.py", line 666, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/opt/miniconda/lib/python3.7/site-packages/pkg_resources/init.py", line 1460, in run_script
exec(script_code, namespace, namespace)
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 422, in
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 413, in main
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 240, in loop_rotations
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 162, in get_cross_correlation_from_coordinate_pair
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 108, in compute_xcorr
File "/opt/miniconda/lib/python3.7/subprocess.py", line 395, in check_output
**kwargs).stdout
File "/opt/miniconda/lib/python3.7/subprocess.py", line 487, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['minccmp', '-xcorr', '-mask', '//tmp//rot_17719/rot_2.mnc', '//tmp//rot_17719/rot_5.mnc', '//tmp//rot_17719/rot_1.mnc']' returned non-zero exit status 1.

To match the co-ordinates between volumes:

autocrop -signed -clobber -debug -from enlarged_mask.mnc test_autocrop.mnc test_world_coord.mnc
GetVolumeBounds:
xspace: start=-5.11522, stop=15.3508
yspace: start=-8.6925, stop=11.7735
zspace: start=-15.0564, stop=5.4096
GetTagBounds:
xspace: start=-5.11522, extent=20.493
yspace: start=-8.6925, extent=20.493
zspace: start=-15.0564, extent=20.493
FixBounds:
xspace: start=-5.11522, extent=20.52
yspace: start=-8.6925, extent=20.52
zspace: start=-15.0564, extent=20.52
ModifyBounds:
xspace: start=-5.11522, extent=20.52
yspace: start=-8.6925, extent=20.52
zspace: start=-15.0564, extent=20.52
Params: -start -180,57,190 -count 760,760,760
Dimension order: 2 1 0
Params: -dimrange zspace=-180,760 -dimrange yspace=57,760 -dimrange xspace=190,760
[autocrop] [minc@mincvm:/media/sf_vmshare/Kat_crp_mnc] [2019-09-21 03:36:19] /opt/minc/1.9.17/bin/mincreshape -clobber -signed test_autocrop.mnc test_world_coord.mnc -dimrange zspace=-180,760 -dimrange yspace=57,760 -dimrange xspace=190,760
Copying chunks:........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Done.

autocrop -signed -clobber -debug -from enlarged_mask.mnc test_autocrop_target.mnc test_world_coord_target.mnc
GetVolumeBounds:
xspace: start=-5.11522, stop=15.3508
yspace: start=-8.6925, stop=11.7735
zspace: start=-15.0564, stop=5.4096
GetTagBounds:
xspace: start=-5.11522, extent=20.493
yspace: start=-8.6925, extent=20.493
zspace: start=-15.0564, extent=20.493
FixBounds:
xspace: start=-5.11522, extent=20.52
yspace: start=-8.6925, extent=20.52
zspace: start=-15.0564, extent=20.52
ModifyBounds:
xspace: start=-5.11522, extent=20.52
yspace: start=-8.6925, extent=20.52
zspace: start=-15.0564, extent=20.52
Params: -start -180,57,190 -count 760,760,760
Dimension order: 2 1 0
Params: -dimrange zspace=-180,760 -dimrange yspace=57,760 -dimrange xspace=190,760
[autocrop] [minc@mincvm:/media/sf_vmshare/Kat_crp_mnc] [2019-09-21 04:34:33] /opt/minc/1.9.17/bin/mincreshape -clobber -signed test_autocrop_target.mnc test_world_coord_target.mnc -dimrange zspace=-180,760 -dimrange yspace=57,760 -dimrange xspace=190,760
Copying chunks:........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Done.

mincinfo enlarged_mask.mnc test_world_coord.mnc test_world_coord_target.mnc
mincinfo enlarged_mask.mnc test_world_coord.mnc test_world_coord_target.mnc
file: enlarged_mask.mnc
image: signed__ short -32768 to 32767
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 759 0.027 -15.0564
yspace 759 0.027 -8.6925
xspace 759 0.027 -5.11522

file: test_world_coord.mnc
image: signed__ short -32768 to 32767
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 760 0.027 -15.06
yspace 760 0.027 -8.701
xspace 760 0.027 -5.11

file: test_world_coord_target.mnc
image: signed__ short -32768 to 32767
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 760 0.027 -15.06
yspace 760 0.027 -8.701
xspace 760 0.027 -5.11

#running rotational minctracc on corrected start spaces

rotational_minctracc.py -m enlarged_mask.mnc test_world_coord.mnc test_world_coord_target.mnc test_minc_trans.fxm test_minc_vol.mnc
TMP: /tmp/
RANGE: 50 INTERVAL: 10
[autocrop] [minc@mincvm:/media/sf_vmshare/Kat_crp_mnc] [2019-09-21 04:42:33] /opt/minc/1.9.17/bin/mincresample test_world_coord.mnc //tmp//rot_17791/rot_0..mnc -start -5.11 -8.701 -15.06 -step 0.2 0.2 0.2 -nelements 103 103 103
Transforming slices:.......................................................................................................Done
[autocrop] [minc@mincvm:/media/sf_vmshare/Kat_crp_mnc] [2019-09-21 04:42:44] /opt/minc/1.9.17/bin/mincresample test_world_coord_target.mnc //tmp//rot_17791/rot_1.mnc -start -5.11 -8.701 -15.06 -step 0.2 0.2 0.2 -nelements 103 103 103
Transforming slices:.......................................................................................................Done
[autocrop] [minc@mincvm:/media/sf_vmshare/Kat_crp_mnc] [2019-09-21 04:42:54] /opt/minc/1.9.17/bin/mincresample enlarged_mask.mnc //tmp//rot_17791/rot_2.mnc -start -5.11522 -8.6925 -15.0564 -step 0.2 0.2 0.2 -nelements 103 103 103
Transforming slices:.......................................................................................................Done
Using positive peak threshold 7.2

Peaks found in the source image (Distance Transform):
[2.19 0.899 3.64 ]
[-2.71 -0.301 -4.06 ]
[-0.05054054 -0.9496487 -2.2708108 ]
[2.39 0.299 0.34 ]
[2.64 1.449 1.19 ]
[2.59 0.399 1.74 ]
Making byte volume...
Using positive peak threshold 3020.42

Peaks found in the source image (blurred image):
[ 0.69 1.699 -2.26 ]
[-1.51 1.499 -2.26 ]
[-1.31 1.099 -1.06 ]
[-0.91 -0.901 -1.06 ]
[-1.11 -1.301 -1.66 ]
Using positive peak threshold 7.2

Peaks found in the target image (Distance Transform):
[-2.71 -1.101 1.54 ]
[-2.3570588 -1.5480589 3.4694118]
[ 3.54 0.499 -3.46 ]
[-2.51 0.499 1.14 ]
[-0.31 -1.9471538 3.8476923]
[-0.21 -0.601 3.94 ]
Making byte volume...
Using positive peak threshold 2945.38

Peaks found in the target image (blurrred image):
[ 0.29 2.099 -2.26 ]
[ 1.29 1.899 -0.86 ]
[ 0.09 -1.101 -1.86 ]
[ 1.89 -0.901 -1.66 ]
Transforming slices:.......................................................................................................Done
Files //tmp//rot_17791/rot_2.mnc and //tmp//rot_17791/rot_5.mnc have different start coordinates (zspace)
Traceback (most recent call last):
File "/opt/miniconda/bin/rotational_minctracc.py", line 4, in
import('pkg_resources').run_script('python-stuffs==0.1.24', 'rotational_minctracc.py')
File "/opt/miniconda/lib/python3.7/site-packages/pkg_resources/init.py", line 666, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/opt/miniconda/lib/python3.7/site-packages/pkg_resources/init.py", line 1460, in run_script
exec(script_code, namespace, namespace)
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 422, in
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 413, in main
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 240, in loop_rotations
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 162, in get_cross_correlation_from_coordinate_pair
File "/opt/miniconda/lib/python3.7/site-packages/python_stuffs-0.1.24-py3.7.egg/EGG-INFO/scripts/rotational_minctracc.py", line 108, in compute_xcorr
File "/opt/miniconda/lib/python3.7/subprocess.py", line 395, in check_output
**kwargs).stdout
File "/opt/miniconda/lib/python3.7/subprocess.py", line 487, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['minccmp', '-xcorr', '-mask', '//tmp//rot_17791/rot_2.mnc', '//tmp//rot_17791/rot_5.mnc', '//tmp//rot_17791/rot_1.mnc']' returned non-zero exit status 1.

@dorkylever dorkylever changed the title rotational_minctracc .py has a type comparison error when comparing world co-ordinates rotational_minctracc .py has a numeric type comparison error when comparing world co-ordinates Sep 21, 2019
@dorkylever
Copy link
Author

In summary,

Using autocrop was the wrong approach as the world coordinates differed too much between my scans and the mask / initial model I was trying to use.

Instead, I was able to fix the start positions by using two sets of minctracc and mincresample, the first one with -tfm_input_sampling specified on mincresample and the second with -like specificied. I'll upload the exact code to the Arkell/Pydpiper repository when I get the chance.

Kind Regards,
Kyle Drover

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

1 participant