bm_experiments.bm_elastix module

Benchmark for Elastix.

See references:


  1. Download compiled executables from

  2. Try to run both executables locally elastix –help and transformix –help

    • add path to the lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/Applications/elastix/lib

    • define permanent path or copy libraries cp /elastix/lib/* /usr/local/lib/


  1. Perform sample image registration:

    $HOME/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
  2. 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:

    $HOME/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


Run the basic ANTs registration with original parameters:

python bm_experiments/         -t ./data-images/pairs-imgs-lnds_histol.csv         -d ./data-images         -o ./results         -elastix $HOME/Applications/elastix/bin         -cfg ./configs/elastix_affine.txt


The origin of VTK coordinate system is in left bottom corner of the image. Also the first dimension is horizontal (swapped to matplotlib)


For proper confirmation see list of Elastix parameters:


If you have any complication with Elastix, see

Klein, Stefan, et al. “Elastix: a toolbox for intensity-based medical image registration.”

IEEE transactions on medical imaging 29.1 (2009): 196-205.

Copyright (C) 2017-2019 Jiri Borovec <>

class bm_experiments.bm_elastix.BmElastix(params)[source]

Bases: birl.benchmark.ImRegBenchmark

Benchmark for Elastix

For the app installation details, see module details.


>>> 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)
>>> shutil.rmtree(path_out, ignore_errors=True)

initialise benchmark


params (dict) – parameters


clean unnecessarily files after the registration


item (dict) – dictionary with regist. information

Return dict

the same or updated regist. info


get registration results - warped registered images and landmarks


item (dict) – dictionary with registration params

Return dict

paths to warped images/landmarks


generate the registration command(s)


item (dict) – dictionary with registration params

Return str|list(str)

the execution commands


prepare BM - copy configurations

static extend_parse(arg_parser)[source]

extent the basic arg parses by some extra required parameters

Return object

static parse_warped_points(path_pts, col_name='OutputPoint')[source]
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

EXEC_ELASTIX = 'elastix'[source]

executable for performing image registration

EXEC_TRANSFX = 'transformix'[source]

executable for performing image/landmarks transformation

NAME_IMAGE_WARPED = 'result.*'[source]

default name of warped image (the image extension cam be changed in the config file)

NAME_LNDS_WARPED = 'outputpoints.txt'[source]

default name of warped landmarks

REQUIRED_PARAMS = ['path_out', 'path_table', 'path_config'][source]

required experiment parameters