File Exchange

image thumbnail

MATLAB Elastix

version (987 KB) by Rob Campbell
Elastix wrappers for MATLAB


Updated 07 Jul 2020

From GitHub

View license on GitHub

MelastiX is a collection of wrappers for the open source image registration suite Elastix. Elastix is cross-platform and is normally called from the system command-line (no GUI). MelastiX allows the elastix and transformix commands to be called from within MATLAB as though they are native MATLAB commands. This has the following advantages:
1. The user can feed in MATLAB matrices instead of image file names and get a MATLAB matrix back as a result.
2. Parameters can be passed in as Elastix text files or as an MelastiX YAML file. The latter provides some error-checking options as the type and possible values of the parameters can be checked.
3. Parameter files can be modified by passing an optional structure as a command-line argument. This makes it easy to explore how changing parameters affects registration accuracy.
4. Handles both 2D and 3D data. Examples are only 2D, though.
To get support or report bugs please e-mail me or start an issue on Github ( Please don't use the comments section below to ask for support.
The image processing toolbox is required to run some of the examples but not to run the registration.

Cite As

Rob Campbell (2021). MATLAB Elastix (, GitHub. Retrieved .

Comments and Ratings (15)

Rob Campbell

I have no immediate plans for adding masks right now. I can see the need and it's a need I likely share but I have no timescale on this. It depends on whether we have projects in-house that absolute require it. I can't imagine it's hard to add. Likely the most challenging thing is coming up with a good way of building masks, which of course is outside the scope of the present tool.

Mohamed Abdelkhalek

Hello, thanks for this great idea. I was just wondering when will the mask capability be added ? and whether there is a workaround to include mask.mhd images in the parameters , you mentioned that it is not currently supported on the git page.




Shigeaki Kanatani

Thank you for your help, Rob. I just found now that invert transform did not go well. I thought invert transform will go well because the normal transform worked well, but actually it is not. I should find a good parameter to move Atlas image to test sample to have a nice invert transform result. Thank you very much.

Rob Campbell

That should work: I do it all the time. When does it fail? Does the example itself not work?

Shigeaki Kanatani

This script is very nice and easy to use. Thank you very much.
I would like to hear your experience because I have a problem in invert transform when I did B-spline transformation. The registered image is perfect, but the points do not move to the place where they should go. Do you know if there is a bug in Elastix when you do inverse transform of B-spline?

Rob Campbell

No, because I implemented this in a really crap way by just calling the Elastix binary.

Nick Durkee

This literally saved my project.

Would it be possible to implement more of the methods in ITK such as demons,morphon etc?


Sorry for my delay. I managed to make it work only by changing the number of dimensions in your 2D examples parameters files.
However, it seems that the program exits because the maximum number of iterations have been reached...
The result is quite good though, I think I just need to take a deeper look into the Elastix documentation to optimize my parameters.
Anyway, thank you a lot.

Rob Campbell

3D definitely works. That's all I use it for, in fact. It sounds like the transformation never happened. Elastix produces a log file when it runs and that will contain the details of what the error is. Take a look at the file. Maybe you aren't telling Elastix that the number of dimensions is 3?


Hi! First of all, thanks for this awesome tool.
I could make your examples work but I'm having an issue with 3D matrices. The registration seems to work but I'm a having this message:
"WARNING: could find no transformed result images in C:\..."
Do you know what could it be?

Andrea Libri

Rob Campbell

Ibraheem, 3D works exactly the same as 2D. Just feed in 3D matrices and in the parameter files set the number of dimensions to 3. Of course (as in 2D) you may need to tweak other parameters to get the most out of the registration. The examples are 2D because it's easier to see the results of the registration.

Ibraheem Al-Dhamari

would be nice if there is a simple example for 3d images e.g. the images provided by matlab registration example

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!