Code covered by the BSD License

B-spline Grid, Image and Point based Registration

Dirk-Jan Kroon (view profile)

26 May 2008 (Updated )

B-spline registration of two 2D / 3D images or corrsp. points, affine and with smooth b-spline grid.

example_2d_affine.m
```% example of 2D affine registration using the lsqnonlin optimizer.

% clean
clear all; close all; clc;

% Read two greyscale images of Lena

% Type of registration error used see registration_error.m
type='d';

% Smooth both images for faster registration
I1s=imfilter(I1,fspecial('gaussian'));
I2s=imfilter(I2,fspecial('gaussian'));

% Parameter scaling of translateX translateY rotate resizeX resizeY
% (ShearXY, ShearYX can also be included add the end of the vector, but
%   because rotation can be seen as a type of shear transform, the scaling
%       of the rotation or shear transform must be very small)
scale=[1 1 1 0.01 0.01];

[x]=lsqnonlin(@(x)affine_registration_image(x,scale,I1s,I2s,type),[0 0 0 100 100],[],[],optimset('Display','iter','MaxIter',100));

% Scale the translation, resize and rotation parameters to the real values
x=x.*scale;

% Make the affine transformation matrix
M=make_transformation_matrix(x(1:2),x(3),x(4:5));

Icor=affine_transform(I1,M,3); % 3 stands for cubic interpolation

% Show the registration results
figure,
subplot(1,3,1), imshow(I1);
subplot(1,3,2), imshow(I2);
subplot(1,3,3), imshow(Icor);
```