Nonrigid and Affine Registration of 2d and 3d images