Search in sources :

Example 11 with PointMatch

use of mpicbg.models.PointMatch in project TrakEM2 by trakem2.

the class RansacRegressionReduceFilter method filter.

@Override
public void filter(final List<PointMatch> candidates, final Collection<PointMatch> inliers) {
    try {
        if (model.filterRansac(candidates, inliers, iterations, maxEpsilon, minInlierRatio, minNumInliers, maxTrust)) {
            model.fit(inliers);
            final double[] minMax = minMax(inliers);
            inliers.clear();
            final Point p1 = new Point(new double[] { minMax[0] });
            final Point p2 = new Point(new double[] { minMax[1] });
            p1.apply(model);
            p2.apply(model);
            inliers.add(new PointMatch(p1, new Point(p1.getW().clone())));
            inliers.add(new PointMatch(p2, new Point(p2.getW().clone())));
        } else
            inliers.clear();
    } catch (final Exception e) {
        inliers.clear();
    }
}
Also used : PointMatch(mpicbg.models.PointMatch) Point(mpicbg.models.Point)

Example 12 with PointMatch

use of mpicbg.models.PointMatch in project TrakEM2 by trakem2.

the class RansacRegressionReduceFilter method minMax.

protected static final double[] minMax(final Iterable<PointMatch> matches) {
    final Iterator<PointMatch> iter = matches.iterator();
    PointMatch m = iter.next();
    double min = m.getP1().getL()[0], max = min;
    while (iter.hasNext()) {
        m = iter.next();
        final double x = m.getP1().getL()[0];
        if (x < min)
            min = x;
        else if (x > max)
            max = x;
    }
    return new double[] { min, max };
}
Also used : PointMatch(mpicbg.models.PointMatch)

Example 13 with PointMatch

use of mpicbg.models.PointMatch in project TrakEM2 by trakem2.

the class TransformMesh method closestSourceAffine.

/**
 * Return the {@link AffineModel2D} used by the triangle enclosing or
 * closest to the passed target location.
 *
 * @param location
 * @return
 */
public AffineModel2D closestSourceAffine(final double[] location) {
    assert location.length == 2 : "2d transform meshs can be applied to 2d points only.";
    final Set<AffineModel2D> s = av.keySet();
    for (final AffineModel2D ai : s) {
        final ArrayList<PointMatch> pm = av.get(ai);
        if (isInSourcePolygon(pm, location))
            return ai;
    }
    /* not in the mesh, find the closest affine */
    double dMin = Double.MAX_VALUE;
    AffineModel2D closestAffine = new AffineModel2D();
    final double x = location[0];
    final double y = location[1];
    for (final AffineModel2D ai : s) {
        final ArrayList<PointMatch> pm = av.get(ai);
        double d = 0;
        for (final PointMatch p : pm) {
            final double[] l = p.getP1().getL();
            final double dx = l[0] - x;
            final double dy = l[1] - y;
            d += Math.sqrt(dx * dx + dy * dy);
        }
        if (d < dMin) {
            dMin = d;
            closestAffine = ai;
        }
    }
    return closestAffine;
}
Also used : PointMatch(mpicbg.models.PointMatch) AffineModel2D(mpicbg.models.AffineModel2D)

Example 14 with PointMatch

use of mpicbg.models.PointMatch in project TrakEM2 by trakem2.

the class TransformMesh method closestTargetAffine.

/**
 * Return the {@link AffineModel2D} used by the triangle enclosing or
 * closest to the passed target location.
 *
 * @param location
 * @return
 */
public AffineModel2D closestTargetAffine(final double[] location) {
    assert location.length == 2 : "2d transform meshs can be applied to 2d points only.";
    final Set<AffineModel2D> s = av.keySet();
    for (final AffineModel2D ai : s) {
        final ArrayList<PointMatch> pm = av.get(ai);
        if (isInConvexTargetPolygon(pm, location))
            return ai;
    }
    /* not in the mesh, find the closest affine */
    double dMin = Double.MAX_VALUE;
    AffineModel2D closestAffine = new AffineModel2D();
    final double x = location[0];
    final double y = location[1];
    for (final AffineModel2D ai : s) {
        final ArrayList<PointMatch> pm = av.get(ai);
        double d = 0;
        for (final PointMatch p : pm) {
            final double[] w = p.getP2().getW();
            final double dx = w[0] - x;
            final double dy = w[1] - y;
            d += Math.sqrt(dx * dx + dy * dy);
        }
        if (d < dMin) {
            dMin = d;
            closestAffine = ai;
        }
    }
    return closestAffine;
}
Also used : PointMatch(mpicbg.models.PointMatch) AffineModel2D(mpicbg.models.AffineModel2D)

Example 15 with PointMatch

use of mpicbg.models.PointMatch in project TrakEM2 by trakem2.

the class MovingLeastSquaresTransform method toDataString.

private final void toDataString(final StringBuilder data) {
    if (AffineModel2D.class.isInstance(model))
        data.append("affine 2");
    else if (TranslationModel2D.class.isInstance(model))
        data.append("translation 2");
    else if (RigidModel2D.class.isInstance(model))
        data.append("rigid 2");
    else if (SimilarityModel2D.class.isInstance(model))
        data.append("similarity 2");
    else if (AffineModel3D.class.isInstance(model))
        data.append("affine 3");
    else
        data.append("unknown");
    data.append(' ').append(alpha);
    // Sort matches, so that they are always written the same way
    // Will help lots git and .zip to reduce XML file size
    final ArrayList<PointMatch> pms = new ArrayList<PointMatch>(matches);
    Collections.sort(pms, SORTER);
    for (final PointMatch m : pms) {
        final double[] p1 = m.getP1().getL();
        final double[] p2 = m.getP2().getW();
        for (int k = 0; k < p1.length; ++k) data.append(' ').append(p1[k]);
        for (int k = 0; k < p2.length; ++k) data.append(' ').append(p2[k]);
        data.append(' ').append(m.getWeight());
    }
}
Also used : PointMatch(mpicbg.models.PointMatch) ArrayList(java.util.ArrayList) TranslationModel2D(mpicbg.models.TranslationModel2D) SimilarityModel2D(mpicbg.models.SimilarityModel2D) Point(mpicbg.models.Point)

Aggregations

PointMatch (mpicbg.models.PointMatch)37 ArrayList (java.util.ArrayList)26 Point (mpicbg.models.Point)24 AffineModel2D (mpicbg.models.AffineModel2D)16 NotEnoughDataPointsException (mpicbg.models.NotEnoughDataPointsException)15 SimilarityModel2D (mpicbg.models.SimilarityModel2D)14 AbstractAffineModel2D (mpicbg.models.AbstractAffineModel2D)12 Patch (ini.trakem2.display.Patch)10 AffineTransform (java.awt.geom.AffineTransform)10 Layer (ini.trakem2.display.Layer)9 Rectangle (java.awt.Rectangle)8 TranslationModel2D (mpicbg.models.TranslationModel2D)7 RigidModel2D (mpicbg.models.RigidModel2D)6 RigidModel2D (mpicbg.trakem2.transform.RigidModel2D)6 TranslationModel2D (mpicbg.trakem2.transform.TranslationModel2D)6 HashMap (java.util.HashMap)5 SIFT (mpicbg.ij.SIFT)5 Feature (mpicbg.imagefeatures.Feature)5 FloatArray2DSIFT (mpicbg.imagefeatures.FloatArray2DSIFT)5 Tile (mpicbg.models.Tile)5