bm_experiments.bm_elastix module

Benchmark for Elastix.

See references:

Installation

  1. Download compiled executables from https://github.com/SuperElastix/elastix/releases

  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/

Example

  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
    

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

Note

If you have any complication with Elastix, see https://github.com/SuperElastix/elastix/wiki/FAQ

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()  
>>> 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

_prepare()[source]

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