bm_experiments.bm_elastix module¶
Benchmark for Elastix.
See references:
- http://elastix.isi.uu.nl/index.php
- https://github.com/SuperElastix/elastix/wiki/Getting-started
- https://blog.yuwu.me/wp-content/uploads/2017/10/elastix_manual_v4.8.pdf
Installation¶
- Download compiled executables from https://github.com/SuperElastix/elastix/releases
- Try to run both executables locally elastix –help and transformix –help
- add path to the lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/Applications/elastix/lib
- define permanent path or copy libraries cp /elastix/lib/* /usr/local/lib/
Example
- Perform sample image registration:
`bash ~/Applications/elastix/bin/elastix -f ./data_images/images/artificial_reference.jpg -m ./data_images/images/artificial_moving-affine.jpg -out ./results/elastix -p ./configs/elastix_affine.txt `
- Besides using transformix for deforming images, you can also use transformix
to evaluate the transformation at some points. This means that the input points are specified in the fixed image domain, since the transformation direction is from fixed to moving image. Perform image/points warping:
`bash ~/Applications/elastix/bin/transformix -tp ./results/elastix/TransformParameters.0.txt -out ./results/elastix -in ./data_images/images/artificial_moving-affine.jpg -def ./data_images/landmarks/artificial_reference.pts `
Usage¶
Run the basic ANTs registration with original parameters:
python bm_experiments/bm_elastix.py -t ./data_images/pairs-imgs-lnds_histol.csv -d ./data_images -o ./results -elastix ~/Applications/elastix/bin -cfg ./configs/elastix_affine.txt
Note
The origin of VTK coordinate system is in left bottom corner of the image. Also the first dimension is horizontal (swapped to matplotlib)
Note
For proper confirmation see list of Elastix parameters: http://elastix.isi.uu.nl/doxygen/parameter.html
- Klein, Stefan, et al. “Elastix: a toolbox for intensity-based medical image registration.”
- IEEE transactions on medical imaging 29.1 (2009): 196-205. http://elastix.isi.uu.nl/marius/downloads/2010_j_TMI.pdf
Copyright (C) 2017-2019 Jiri Borovec <jiri.borovec@fel.cvut.cz>
-
class
bm_experiments.bm_elastix.
BmElastix
(params)[source]¶ Bases:
birl.benchmark.ImRegBenchmark
Benchmark for Elastix
For the app installation details, see module details.
Example
>>> from birl.utilities.data_io import create_folder, update_path >>> path_out = create_folder('temp_results') >>> fn_path_conf = lambda n: os.path.join(update_path('configs'), n) >>> path_csv = os.path.join(update_path('data_images'), 'pairs-imgs-lnds_mix.csv') >>> params = {'path_out': path_out, ... 'path_table': path_csv, ... 'nb_workers': 1, ... 'unique': False, ... 'path_elastix': '.', ... 'path_config': fn_path_conf('elastix_affine.txt')} >>> benchmark = BmElastix(params) >>> benchmark.run() # doctest: +SKIP >>> del benchmark >>> shutil.rmtree(path_out, ignore_errors=True)
initialise benchmark
Parameters: params (dict) – parameters -
_clear_after_registration
(item)[source]¶ clean unnecessarily files after the registration
Parameters: item (dict) – dictionary with regist. information Return dict: the same or updated regist. info
-
_extract_warped_image_landmarks
(item)[source]¶ get registration results - warped registered images and landmarks
Parameters: item (dict) – dictionary with registration params Return dict: paths to warped images/landmarks
-
_generate_regist_command
(item)[source]¶ generate the registration command(s)
Parameters: item (dict) – dictionary with registration params Return str|list(str): the execution commands
-
static
extend_parse
(arg_parser)[source]¶ extent the basic arg parses by some extra required parameters
Return object:
-
COMMAND_REGISTRATION
= '%(exec_elastix)s -f %(target)s -m %(source)s -out %(output)s -p %(config)s'[source]¶ command template for image registration
-
COMMAND_TRANSFORMATION
= '%(exec_transformix)s -tp %(output)s/TransformParameters.0.txt -out %(output)s -in %(source)s -def %(landmarks)s'[source]¶ command template for image/landmarks transformation
-