@Test public void testBuildTransformSpec() throws Exception { final ThinPlateSplineClient.Parameters parameters = new ThinPlateSplineClient.Parameters(); final double[] sourceXs = { 0.0, 22.0 }; final double[] sourceYs = { 0.0, 22.0 }; final double[] targetXs = { 10.0, 32.0 }; final double[] targetYs = { 10.0, 32.0 }; final List<Double> landmarkValues = new ArrayList<>(); for (int i = 0; i < sourceXs.length; i++) { landmarkValues.add(sourceXs[i]); landmarkValues.add(sourceYs[i]); } for (int i = 0; i < targetXs.length; i++) { landmarkValues.add(targetXs[i]); landmarkValues.add(targetYs[i]); } parameters.numberOfLandmarks = sourceXs.length; parameters.landmarkValues = landmarkValues; final ThinPlateSplineClient client = new ThinPlateSplineClient(parameters); final LeafTransformSpec transformSpec = client.buildTransformSpec(); final CoordinateTransform transform = transformSpec.getNewInstance(); final double testDelta = 0.0001; for (int i = 0; i < sourceXs.length; i++) { final double[] testResult = transform.apply(new double[] { sourceXs[i], sourceYs[i] }); Assert.assertEquals("invalid x for landmark " + i, targetXs[i], testResult[0], testDelta); Assert.assertEquals("invalid y for landmark " + i, targetYs[i], testResult[1], testDelta); } }
public LeafTransformSpec buildTransformSpec() throws Exception { final double[][] sourcePoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; final double[][] targetPoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; int sourceValueIndex = 0; int targetValueIndex = parameters.numberOfLandmarks * parameters.numberOfDimensions; for (int landmark = 0; landmark < parameters.numberOfLandmarks; landmark++){ for (int dimension = 0; dimension < parameters.numberOfDimensions; dimension++) { sourcePoints[dimension][landmark] = parameters.landmarkValues.get(sourceValueIndex); targetPoints[dimension][landmark] = parameters.landmarkValues.get(targetValueIndex); sourceValueIndex++; targetValueIndex++; } } final ThinPlateR2LogRSplineKernelTransform kernelTransform = new ThinPlateR2LogRSplineKernelTransform(parameters.numberOfDimensions, sourcePoints, targetPoints); kernelTransform.setDoAffine(parameters.computeAffine); kernelTransform.solve(); final ThinPlateSplineTransform serializableTransform = new ThinPlateSplineTransform(kernelTransform); final LeafTransformSpec transformSpec = new LeafTransformSpec(serializableTransform.getClass().getName(), serializableTransform.toDataString()); LOG.info("buildTransformSpec: returning\n{}", transformSpec.toJson()); return transformSpec; }
ThinPlateSplineClient { public LeafTransformSpec buildTransformSpec() throws Exception { final double[][] sourcePoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; final double[][] targetPoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; int sourceValueIndex = 0; int targetValueIndex = parameters.numberOfLandmarks * parameters.numberOfDimensions; for (int landmark = 0; landmark < parameters.numberOfLandmarks; landmark++){ for (int dimension = 0; dimension < parameters.numberOfDimensions; dimension++) { sourcePoints[dimension][landmark] = parameters.landmarkValues.get(sourceValueIndex); targetPoints[dimension][landmark] = parameters.landmarkValues.get(targetValueIndex); sourceValueIndex++; targetValueIndex++; } } final ThinPlateR2LogRSplineKernelTransform kernelTransform = new ThinPlateR2LogRSplineKernelTransform(parameters.numberOfDimensions, sourcePoints, targetPoints); kernelTransform.setDoAffine(parameters.computeAffine); kernelTransform.solve(); final ThinPlateSplineTransform serializableTransform = new ThinPlateSplineTransform(kernelTransform); final LeafTransformSpec transformSpec = new LeafTransformSpec(serializableTransform.getClass().getName(), serializableTransform.toDataString()); LOG.info("buildTransformSpec: returning\n{}", transformSpec.toJson()); return transformSpec; } }
ThinPlateSplineClient { public LeafTransformSpec buildTransformSpec() throws Exception { final double[][] sourcePoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; final double[][] targetPoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; int sourceValueIndex = 0; int targetValueIndex = parameters.numberOfLandmarks * parameters.numberOfDimensions; for (int landmark = 0; landmark < parameters.numberOfLandmarks; landmark++){ for (int dimension = 0; dimension < parameters.numberOfDimensions; dimension++) { sourcePoints[dimension][landmark] = parameters.landmarkValues.get(sourceValueIndex); targetPoints[dimension][landmark] = parameters.landmarkValues.get(targetValueIndex); sourceValueIndex++; targetValueIndex++; } } final ThinPlateR2LogRSplineKernelTransform kernelTransform = new ThinPlateR2LogRSplineKernelTransform(parameters.numberOfDimensions, sourcePoints, targetPoints); kernelTransform.setDoAffine(parameters.computeAffine); kernelTransform.solve(); final ThinPlateSplineTransform serializableTransform = new ThinPlateSplineTransform(kernelTransform); final LeafTransformSpec transformSpec = new LeafTransformSpec(serializableTransform.getClass().getName(), serializableTransform.toDataString()); LOG.info("buildTransformSpec: returning\n{}", transformSpec.toJson()); return transformSpec; } ThinPlateSplineClient(final Parameters parameters); }
ThinPlateSplineClient { public LeafTransformSpec buildTransformSpec() throws Exception { final double[][] sourcePoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; final double[][] targetPoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; int sourceValueIndex = 0; int targetValueIndex = parameters.numberOfLandmarks * parameters.numberOfDimensions; for (int landmark = 0; landmark < parameters.numberOfLandmarks; landmark++){ for (int dimension = 0; dimension < parameters.numberOfDimensions; dimension++) { sourcePoints[dimension][landmark] = parameters.landmarkValues.get(sourceValueIndex); targetPoints[dimension][landmark] = parameters.landmarkValues.get(targetValueIndex); sourceValueIndex++; targetValueIndex++; } } final ThinPlateR2LogRSplineKernelTransform kernelTransform = new ThinPlateR2LogRSplineKernelTransform(parameters.numberOfDimensions, sourcePoints, targetPoints); kernelTransform.setDoAffine(parameters.computeAffine); kernelTransform.solve(); final ThinPlateSplineTransform serializableTransform = new ThinPlateSplineTransform(kernelTransform); final LeafTransformSpec transformSpec = new LeafTransformSpec(serializableTransform.getClass().getName(), serializableTransform.toDataString()); LOG.info("buildTransformSpec: returning\n{}", transformSpec.toJson()); return transformSpec; } ThinPlateSplineClient(final Parameters parameters); static void main(final String[] args); LeafTransformSpec buildTransformSpec(); }
ThinPlateSplineClient { public LeafTransformSpec buildTransformSpec() throws Exception { final double[][] sourcePoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; final double[][] targetPoints = new double[parameters.numberOfDimensions][parameters.numberOfLandmarks]; int sourceValueIndex = 0; int targetValueIndex = parameters.numberOfLandmarks * parameters.numberOfDimensions; for (int landmark = 0; landmark < parameters.numberOfLandmarks; landmark++){ for (int dimension = 0; dimension < parameters.numberOfDimensions; dimension++) { sourcePoints[dimension][landmark] = parameters.landmarkValues.get(sourceValueIndex); targetPoints[dimension][landmark] = parameters.landmarkValues.get(targetValueIndex); sourceValueIndex++; targetValueIndex++; } } final ThinPlateR2LogRSplineKernelTransform kernelTransform = new ThinPlateR2LogRSplineKernelTransform(parameters.numberOfDimensions, sourcePoints, targetPoints); kernelTransform.setDoAffine(parameters.computeAffine); kernelTransform.solve(); final ThinPlateSplineTransform serializableTransform = new ThinPlateSplineTransform(kernelTransform); final LeafTransformSpec transformSpec = new LeafTransformSpec(serializableTransform.getClass().getName(), serializableTransform.toDataString()); LOG.info("buildTransformSpec: returning\n{}", transformSpec.toJson()); return transformSpec; } ThinPlateSplineClient(final Parameters parameters); static void main(final String[] args); LeafTransformSpec buildTransformSpec();  }