Search in sources :

Example 16 with NotEnoughDataPointsException

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]);
}
Also used : PointMatch(mpicbg.models.PointMatch) NotEnoughDataPointsException(mpicbg.models.NotEnoughDataPointsException) ArrayList(java.util.ArrayList) Point(mpicbg.models.Point) SimilarityModel2D(mpicbg.models.SimilarityModel2D)

Aggregations

NotEnoughDataPointsException (mpicbg.models.NotEnoughDataPointsException)16 ArrayList (java.util.ArrayList)14 PointMatch (mpicbg.models.PointMatch)13 Point (mpicbg.models.Point)12 SimilarityModel2D (mpicbg.models.SimilarityModel2D)12 AffineModel2D (mpicbg.models.AffineModel2D)10 Patch (ini.trakem2.display.Patch)8 AbstractAffineModel2D (mpicbg.models.AbstractAffineModel2D)8 Layer (ini.trakem2.display.Layer)7 Rectangle (java.awt.Rectangle)7 IllDefinedDataPointsException (mpicbg.models.IllDefinedDataPointsException)6 AffineTransform (java.awt.geom.AffineTransform)5 SIFT (mpicbg.ij.SIFT)5 Feature (mpicbg.imagefeatures.Feature)5 FloatArray2DSIFT (mpicbg.imagefeatures.FloatArray2DSIFT)5 RigidModel2D (mpicbg.models.RigidModel2D)5 TranslationModel2D (mpicbg.models.TranslationModel2D)5 RigidModel2D (mpicbg.trakem2.transform.RigidModel2D)5 TranslationModel2D (mpicbg.trakem2.transform.TranslationModel2D)5 ExecutorService (java.util.concurrent.ExecutorService)3