/** * @param permuted * @return */ private static IntervalIterator createIntervalIterator( final RandomAccessibleInterval<?> permuted) { final long[] dims = new long[permuted.numDimensions()]; permuted.dimensions(dims); dims[0] = 1; dims[1] = 1; final IntervalIterator ii = new IntervalIterator(dims); return ii; }
public Cursor(final RandomAccessibleInterval<U> ra) { m_ra = ra.randomAccess(); m_numPixel = numPixels(ra); m_lastPos = new long[ra.numDimensions()]; for (int i = 0; i < m_lastPos.length; i++) { m_lastPos[i] = ra.dimension(i) - 1; } m_breaks = new long[ra.numDimensions()]; ra.dimensions(m_breaks); for (int i = 1; i < m_breaks.length; i++) { m_breaks[i] *= m_breaks[i - 1]; } setToOrigin(); }
/** Compute the inverse Hessian matrix from the the steepest descent images. */ public static <T extends RealType<T>> double[][] computeInverseHessian( final RandomAccessibleInterval<T> descent) { final int n = descent.numDimensions() - 1; final int numParameters = (int) descent.dimension(n); final long[] dim = new long[n + 1]; descent.dimensions(dim); dim[n] = 1; final LocalizingIntervalIterator pos = new LocalizingIntervalIterator(dim); final RandomAccess<T> r = descent.randomAccess(); final double[] deriv = new double[numParameters]; final double[][] H = new double[numParameters][numParameters]; while (pos.hasNext()) { pos.fwd(); r.setPosition(pos); for (int p = 0; p < numParameters; ++p) { deriv[p] = r.get().getRealDouble(); r.fwd(n); } for (int i = 0; i < numParameters; ++i) for (int j = 0; j < numParameters; ++j) H[i][j] += deriv[i] * deriv[j]; } return new Matrix(H).inverse().getArray(); }