4.77778

4.8 | 11 ratings Rate this file 159 downloads (last 30 days) File Size: 6.83 MB File ID: #21451

multimodality non-rigid demon algorithm image registration

by Dirk-Jan Kroon

 

16 Sep 2008 (Updated 01 Oct 2009)

Code covered by the BSD License  

non-rigid 2D and 3D image registration with demon (fluid) algorithm, extended with modality transf.

Download Now | Watch this File

File Information
Description

This function will perform demon registration which is an type of fast non-rigid fluid like registration between two 2D or 3D images. Registration between different (MRI) modalities is also supported, through a function which transform one image modality so it looks likes the modality of the second image.

The demon registration is described by the paper of Thirion 1998 and extended by Cachier 1999 and He Wang 2005.

Basic algorithm: On each pixel a velocity (movement) is defined with use of the intensity differences and gradient information. This velocity field is smoothed by an Gaussian, and iteratively used to transform the moving image, and register on to the static image. (Easy to understand code example in file basic_demon_example.m)

Instead of using the basic equations for the "demonregistration" function, we have rewritten it to be used by an limit memory BFGS optimizer in an iterative and multi-resolution way, with also support of diffusion regularization. (see also Tom Vercauteren et al. "Non-parametric Diffeomorphic Image..." )

Transforming one modality into the fake modality of the other image is done with use of 2D mutual histograms between regions of both images, and choosing the grey values which have the highest correlation. D. Kroon et al. "MRI Modality Transformation in Demon Registration" (MutualTransform.m)

See the screenshot for an example result.

Usage:
The functions register_images.m and register_volumes.m are easy to use, and will fit most applications.
First compile the c-code : compile_c_files.m.

Notes:
- All the mex-code is multi-threaded and is tested on both Windows and Linux.
- Please leave comments and report bugs

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.6 (R2008a)
Zip File Content  
Other Files
basic_demon_example.m,
compile_c_files.m,
functions/backwards2forwards.m,
functions/backwards2forwards_2d_double.c,
functions/backwards2forwards_2d_double.m,
functions/backwards2forwards_3d_double.c,
functions/backwards2forwards_3d_single.c,
functions/demons_energy.m,
functions/fminlbfgs.m,
functions/imgaussian.m,
functions/imresize3d.m,
functions/mutual_histogram_double.c,
functions/mutual_histogram_double.m,
functions/mutual_histogram_single.c,
functions/mutual_transform_2d_double.asv,
functions/mutual_transform_2d_double.c,
functions/mutual_transform_2d_double.m,
functions/mutual_transform_3d_double.asv,
functions/mutual_transform_3d_double.c,
functions/mutual_transform_3d_single.asv,
functions/mutual_transform_3d_single.c,
functions/MutualTransform.m,
functions/showcs3.fig,
functions/showcs3.m,
functions/store_transf.m,
functions/strain.m,
functions_affine/affine_error_3d_double.c,
functions_affine/affine_error_3d_single.c,
functions_affine/affine_registration_error.m,
functions_affine/affine_registration_image.m,
functions_affine/affine_transform.m,
functions_affine/affine_transform_2d_double.c,
functions_affine/affine_transform_2d_double.m,
functions_affine/affine_transform_3d_double.c,
functions_affine/affine_transform_3d_single.c,
functions_affine/image_difference.m,
functions_affine/image_interpolation.c,
functions_affine/image_interpolation.h,
functions_affine/make_transformation_matrix.m,
functions_nonrigid/image_interpolation.c,
functions_nonrigid/image_interpolation.h,
functions_nonrigid/movepixels.m,
functions_nonrigid/movepixels_2d_double.c,
functions_nonrigid/movepixels_2d_double.m,
functions_nonrigid/movepixels_3d_double.c,
functions_nonrigid/movepixels_3d_single.c,
images/brain_FA.png,
images/brain_FLAIR.png,
images/brain_MD.png,
images/brain_T1.png,
images/brain_T1_wave.png,
images/brain_T2.png,
images/brain_T2_wave.png,
images/checkboard2.png,
images/checkboard3.png,
images/checkboard4.png,
images/get_example_data.m,
images/lenag1.png,
images/lenag2.png,
images/lenag3.png,
images/modtest1.png,
images/modtest2.png,
images/modtest3.png,
images/wave_field.mat,
license.txt,
literature/Kroon_Paper_Boston.pdf,
literature/Kroon_Poster_Boston.pdf,
register_images.m,
register_volumes.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (31)
17 Sep 2008 Dirk-Jan Kroon

There is a small bug that images with odd valued dimensions now gives an error. Will be updated tomorrow...

13 Oct 2008 K K

Hi, seems it is good. But I cannot complie it..is it due to the Matlab version? I have R2006a and Matlab 6.5. both cannot complie. Thanks a lot!

13 Oct 2008 K K

I try to complie it with other machine, thanks. Would like to know if you have version for color image~ Thanks~

13 Oct 2008 Dirk-Jan Kroon

* K K,
Color image registration example:
C1=im2double(imread('lena1.jpg'));
    C2=im2double(imread('lena2.jpg'));
    [I3,Tx,Ty]=demonregistration(rgb2gray(C1),rgb2gray(C2),[],false);
    C3 = zeros(size(C1));
    C3(:,:,1)=movepixels(C1(:,:,1),Tx,Ty);
    C3(:,:,2)=movepixels(C1(:,:,2),Tx,Ty);
    C3(:,:,3)=movepixels(C1(:,:,3),Tx,Ty);
    imshow(C3,[]); title('Registered image');

13 Oct 2008 K K

thanks a lot. I know what you mean. But what I mean is change the Idiff as something like this:
Idiff_color=M_color-S_color;
Idiff = Idiff_color(:,1)+Idiff_color(:,2)+Idiff_color(:,3) ; Idiff = Idiff/3 ;
where M_color is color version of M previous obtained.

21 Oct 2008 Franz Rudolf

I am a student and want to learn something about nonrigid registration techniques. Can anybody tell me which transformation model it uses (is the Thin Plate Transformation the same as the B Spline?)

21 Oct 2008 K K

I test the code by adding the following:

% Register image 1 to image 2
[I3,Tx,Ty]=demonregistration(I1,I2,[],true);

[h,w] = size(Tx) ;
Ty = zeros(h,w) ;
Tx = 5*ones(h,w) ;

I3=movepixels(I1,Tx,Ty);

but the result is not what I expected.
The image is shifted up instead of left~~~
Indeed what is Tx,Ty doing? is it a deformation field? forward or backward warping?

21 Oct 2008 K K

It seems that the Tx and Ty are indeed swapped???
I have tried the code on a very simple line registration, the "registered image" is correct, however, Tx and Ty seem being swapped...

22 Oct 2008 Dirk-Jan Kroon

*K K,
Thanks for your comments. The method uses backward warping. Today, I will look at my code if I accidentally swapped Tx and Ty. This week or the next I will upload a new version, which can be used with any Matlab optimizer.

* Franz Rudolf
This transformation algorithm is called: non-parametric, iconic feature based, using point features.

28 Oct 2008 Assaf cohen

Will this be good to register a degraded image due to Atmospheric Turbulence to a reference frame (avarage of say 10 degraded images) and this how to improve the quality of the video?

31 Oct 2008 Dirk-Jan Kroon

Please upgrade to version 10b if you experience Matlab crashes with affine transformation in version 10.

07 Nov 2008 Michel Kocher

Hello, I am using Matlab from a Mac and the files system.h and process.h do not seem to be available. How can I compile movepixels_2d_double.c

07 Nov 2008 Dirk-Jan Kroon

*Michel Kocher...
After this weekend i will add a (previous) single threaded version, which works with the Mac computer.

13 Nov 2008 yichen fan

Having an error when compile the program:

??? Error using ==> mex
Unable to complete successfully

Error in ==> compile_c_files at 4
    mex(files(i).name,'-v');

Error in ==> basic_demon_example at 7
compile_c_files

Is that a common error?
I am using Matlab ver 7.1.0.246(R14) SP3

13 Nov 2008 Dirk-Jan Kroon

*yichen fan
I have never seen this error.
Please have a look at the help of Mex : http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/mex.htm

Maybee Mex or the LCC compiler is not installed with Matlab.
You can also trie the single threaded c-code files...

18 Feb 2009 nor ki

works pretty fine!

02 Jul 2009 Alper Yaman

Can you add single thread codes of the latest version. I am using linux and it gives error.
In addition, as using in linux, compilation of mex files gives error just because of the comment lines. You can avoid such errors by replacing "//" with "/*" and of course add "*/" at the end of the line.

07 Jul 2009 Cheng Lu

good job!

23 Jul 2009 Geoff  
12 Aug 2009 jichao zhao

Could you please make good examples for 3D rigid and nonrigid registration which demonstrate how to set parameters for registration? thanks, jichao

17 Aug 2009 jichao zhao

Hi, Sir, your codes are definitely good. When I use your 3D example in register_volumes, the results shown by showcs3
looks weird. Also the values range from -0.2 to 0.3 for example.
Can you explain why it. On the other hand, when I used Ireg2=movepixels(Istatic,Fx,Fy,Fz); showcs3(Ireg2);
Ireg2, however, turns out to be surprising good. thanks.

20 Aug 2009 Adeola

Hi Sir, your work is very good & relevant. Im still a beginner in Matlab environment. Im working on a project that is related to your work. I tried running the codes but for the basic_demon_example, it gave me an error message at line 50, that is, [M=movepixels(I1,Tx,Ty);]. Can you pls help me? Hoping to hear from you soonest.

04 Dec 2009 gx

Good work. Thank you.

One question: When you determine the bin size in function "registration_error_mutual_info", you use:

bins=round(numel(V)^(1/ndims(V)));

May I know what this formulation is obtained?

04 Dec 2009 gx

I meant how the equation "bins=round(numel(V)^(1/ndims(V)));" is obtained? Is it based on some existing publication?

05 Dec 2009 Dirk-Jan Kroon

*gx,

The equation "bins=round(numel(V)^(1/ndims(V)));" is not from literature. You can also use a fix bin size of 255, or so.

- Mutual information only works if there are overlaps in the histogram bins.
- More histogram bins will give better registration accuracy.
Thus this equation gives a good trade-off based on the number of available pixels ...

11 Jan 2010 Rob Campbell  
11 Jan 2010 Rob Campbell  
11 Jan 2010 Rob Campbell

oops, two ratings. But I do like the program!

18 Jan 2010 Yin Yang

Hello, I know it may be a stupid, but I would like to find a function which could compute a pixel say, (x1, y1) in the moving image 's location in the static image, say (x2, y2). It seems to me that the (x1, y1) and (x2, y2) are related through the so-called transformation . Could you explain the detailed relationship among them and what exactly the direction of x, y and z in your code? (from left to right, up to down and top tp buttom?) Thanks

26 Jan 2010 LI guang

I ran the example of multi-registration.but the result is not correct.The pixels of floating image turned to be choas when I ran that multi-registration.So is there something wrong about the multi-registration codes?

29 Jan 2010 LI guang

sorry i made a mistake .The result in multi-registration is also good

Please login to add a comment or rating.
Updates
18 Sep 2008

Dimension bug fixed, and speed increased.

24 Oct 2008

Algorithm rewritten to be used with Matlab Optimizers

10 Nov 2008

Add single threaded MEX code

25 Mar 2009

Out of the box registration now available and also multiple modalities support through modality transformation

14 Jul 2009

Now Linux multi-threading compatible, added cubic interpolation.

16 Jul 2009

3D cubic interpolation bug fixed...

14 Aug 2009

Fixed major bug in 3D registration by adding lost "uz direction" to error term reported by Vivek. Fixed single cubic interpolation bug.

08 Sep 2009

Fix Gaussian Filter

01 Oct 2009

Linux Ubuntu Tested

Tag Activity for this File
Tag Applied By Date/Time
transforms Dirk-Jan Kroon 22 Oct 2008 10:19:43
nonrigid image registration Dirk-Jan Kroon 22 Oct 2008 10:19:43
nonrigid Dirk-Jan Kroon 22 Oct 2008 10:19:43
registration Dirk-Jan Kroon 22 Oct 2008 10:19:43
demon Dirk-Jan Kroon 22 Oct 2008 10:19:43
demons Dirk-Jan Kroon 22 Oct 2008 10:19:43
nonrigid volume registration Dirk-Jan Kroon 24 Oct 2008 09:29:15
2d Cristina McIntire 10 Nov 2008 11:37:12
3d Cristina McIntire 10 Nov 2008 11:37:16
2d Simone Balocco 24 Feb 2009 09:23:09
mri Dirk-Jan Kroon 25 Mar 2009 15:57:50
2d Dirk-Jan Kroon 25 Mar 2009 15:57:50
modalities Dirk-Jan Kroon 25 Mar 2009 15:57:50
modality transformation Dirk-Jan Kroon 25 Mar 2009 15:57:50
fluid registration Dirk-Jan Kroon 25 Mar 2009 15:57:50
fluid Dirk-Jan Kroon 25 Mar 2009 15:57:50
3d Dirk-Jan Kroon 25 Mar 2009 15:57:50
multiple modalities Dirk-Jan Kroon 25 Mar 2009 15:57:50
2d Geoff 23 Jul 2009 15:35:32
3d Geoff 23 Jul 2009 15:35:34
3d w w 08 Dec 2009 10:51:05
2d w w 08 Dec 2009 10:51:08
3d Yin Yang 18 Jan 2010 22:52:02
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com