double alignStep(final RandomAccessibleInterval<T> image) { // compute error image = warped image - template computeDifference(Views.extendBorder(image), currentTransform, template, error); // compute transform parameter update final double[] gradient = new double[numParameters]; for (int p = 0; p < numParameters; ++p) { final Cursor<T> err = Views.flatIterable(error).cursor(); for (final T t : Views.flatIterable(Views.hyperSlice(descent, n, p))) gradient[p] += t.getRealDouble() * err.next().getRealDouble(); } final double[] dp = new double[numParameters]; LinAlgHelpers.mult(Hinv, gradient, dp); // udpate transform currentTransform.preConcatenate(warpFunction.getAffine(dp)); // return norm of parameter update vector return LinAlgHelpers.length(dp); }
public Align(final RandomAccessibleInterval<T> template, final ImgFactory<T> factory) { this.template = template; final T type = Util.getTypeFromInterval(template); n = template.numDimensions(); warpFunction = new AffineWarp(n); numParameters = warpFunction.numParameters(); currentTransform = new AffineTransform(n); final long[] dim = new long[n + 1]; for (int d = 0; d < n; ++d) dim[d] = template.dimension(d); dim[n] = n; final Img<T> gradients = factory.create(dim, type); gradients(Views.extendBorder(template), gradients); dim[n] = numParameters; descent = factory.create(dim, type); computeSteepestDescents(gradients, warpFunction, descent); Hinv = computeInverseHessian(descent); error = factory.create(template, type); }