I'm trying to make an automatic non-rigid image registration using B-Splines as a deformation model, but I'm having some problems:
Here is my MATLAB implementation:
function ref_coeff = refine_coeff_grid(c, ft, delta)
%c -- Control points
%ft -- image to be transformed
%delta -- spacing between the control points
[X,Y]=ndgrid(-delta:delta:(size(ft, 1) +(delta*2)), -delta:delta:(size(ft, 2)+(delta*2)));
[r, co, s] = size(c);
i = 2:(r-2);
j = 2:(co-2);
new_c = zeros(2*(r-3)+3, 2*(co-3)+3, s);
new_c(:, :, 1) = X;
new_c(:, :, 2) = Y;
new_c(2*i, 2*j, :) = (c(i-1, j-1, :) + c(i-1, j+1, :) + c(i+1, j-1, :) + c(i+1, j+1, :) + ...
6*(c(i-1, j, :) + c(i, j-1, :) + c(i, j+1, :) + c(i+1, j, :)) + 36*c(i, j, :))/64;
new_c(2*i, 2*j+1, :) = (c(i-1, j, :) + c(i-1, j+1, :) + c(i+1, j, :) + c(i+1, j+1, :) + 6*c(i, j, :) + 6*c(i, j+1, :))/16;
new_c(2*i+1, 2*j, :) = (c(i, j-1, :) + c(i, j+1, :) + c(i+1, j-1, :) + c(i+1, j+1, :) + 6*c(i, j, :) + 6*c(i+1, j, :))/16;
new_c(2*i+1, 2*j+1, :) = (c(i, j, :) + c(i, j+1, :) + c(i+1, j, :) + c(i+1, j+1, :))/4;
ref_coeff = new_c;
end
What am I doing wrong?
There is a good implementation of the Rueckert et al (1999) b-spline registration available on matlab central, written by Dirk-Jan Kroon.
I would advise you to make use of existing implementations like this since writing a classic registration algorithm from scratch means re-inventing the wheel.
Note that this b-spline registration implementation expects coarsely (e.g. rigid or affine) pre-registered data. It won't work if reference and target are e.g. completely differently scaled or strongly rotated etc. So pre-register first.