% This function will turn a backward transformation field in to a
% forward transformation field, using gaussian kernel splatting.
% Thus when you have transformed image1 into image2 with the Rueckert
% Registration, this function can reverse the vectorField allowing the
% transformation of image2 into image 1.
% Note: Some small interpolation artifacts will be present, thus derivatives
% of the transformation field used for strain measurements are less reliable.
% B: The backward transformation fields
% F: The forward transformation fields
% Function is written by D.Kroon University of Twente (November 2008)
if(ndims(B)==3) % Detect if 2D or 3D
% Gaussian kernel (Must be symetric and odd in size)
[x,y,z] = ndgrid(-3:3,-3:3,-3:3);
H = exp(-(x.*x/2/sigma^2 + y.*y/2/sigma^2 + z.*z/2/sigma^2)); H = H/sum(H(:));