use of mpicbg.models.NotEnoughDataPointsException in project TrakEM2 by trakem2.
the class Render method sampleAverageScale.
/**
* Sample the average scaling of a given {@link CoordinateTransform} by transferring
* a set of point samples using the {@link CoordinateTransform} and then
* least-squares fitting a {@link SimilarityModel2D} to it.
*
* @param ct
* @param width of the samples set
* @param height of the samples set
* @param dx spacing between samples
*
* @return average scale factor
*/
protected static final double sampleAverageScale(final CoordinateTransform ct, final int width, final int height, final double dx) {
final ArrayList<PointMatch> samples = new ArrayList<PointMatch>();
for (double y = 0; y < height; y += dx) {
for (double x = 0; x < width; x += dx) {
final Point p = new Point(new double[] { x, y });
p.apply(ct);
samples.add(new PointMatch(p, p));
}
}
final SimilarityModel2D model = new SimilarityModel2D();
try {
model.fit(samples);
} catch (final NotEnoughDataPointsException e) {
e.printStackTrace(System.err);
return 1;
}
final double[] data = new double[6];
model.toArray(data);
return Math.sqrt(data[0] * data[0] + data[1] * data[1]);
}
Aggregations