use of jitk.spline.ThinPlateR2LogRSplineKernelTransform in project TrakEM2 by trakem2.
the class ThinPlateSplineTransform method init.
@Override
public void init(final String data) throws NumberFormatException {
final String[] fields = data.split("\\s+");
int i = 0;
final int ndims = Integer.parseInt(fields[++i]);
final int nLm = Integer.parseInt(fields[++i]);
double[][] aMtx = null;
double[] bVec = null;
if (fields[i + 1].equals("null")) {
// System.out.println(" No affines " );
++i;
} else {
aMtx = new double[ndims][ndims];
bVec = new double[ndims];
final double[] values;
try {
values = decodeBase64(fields[++i], ndims * ndims + ndims);
} catch (final DataFormatException e) {
throw new NumberFormatException("Failed decoding affine matrix.");
}
int l = -1;
for (int k = 0; k < ndims; k++) for (int j = 0; j < ndims; j++) {
aMtx[k][j] = values[++l];
}
for (int j = 0; j < ndims; j++) {
bVec[j] = values[++l];
}
}
final double[] values;
try {
values = decodeBase64(fields[++i], 2 * nLm * ndims);
} catch (final DataFormatException e) {
throw new NumberFormatException("Failed decoding landmarks and weights.");
}
int k = -1;
// parse control points
final double[][] srcPts = new double[ndims][nLm];
for (int l = 0; l < nLm; l++) for (int d = 0; d < ndims; d++) {
srcPts[d][l] = values[++k];
}
// parse control point coordinates
int m = -1;
final double[] dMtxDat = new double[nLm * ndims];
for (int l = 0; l < nLm; l++) for (int d = 0; d < ndims; d++) {
dMtxDat[++m] = values[++k];
}
tps = new ThinPlateR2LogRSplineKernelTransform(srcPts, aMtx, bVec, dMtxDat);
}
use of jitk.spline.ThinPlateR2LogRSplineKernelTransform in project TrakEM2 by trakem2.
the class ElasticLayerAlignment method makeTPS.
protected static final ThinPlateSplineTransform makeTPS(final Set<PointMatch> matches) throws Exception {
final double[][] srcPts = new double[2][matches.size()];
final double[][] tgtPts = new double[2][matches.size()];
int i = 0;
for (final PointMatch match : matches) {
final double[] srcPt = match.getP1().getL();
final double[] tgtPt = match.getP2().getW();
srcPts[0][i] = srcPt[0];
srcPts[1][i] = srcPt[1];
tgtPts[0][i] = tgtPt[0];
tgtPts[1][i] = tgtPt[1];
++i;
}
final ThinPlateR2LogRSplineKernelTransform tps = new ThinPlateR2LogRSplineKernelTransform(2, srcPts, tgtPts);
return new ThinPlateSplineTransform(tps);
}
Aggregations