Search in sources :

Example 6 with AffineModel2D

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

the class Render method createScaleLevelTransform.

/**
 * Create an affine transformation that compensates for both scale and
 * pixel shift of a mipmap level that was generated by top-left pixel
 * averaging.
 *
 * @param scaleLevel
 * @return
 */
protected static final AffineModel2D createScaleLevelTransform(final int scaleLevel) {
    final AffineModel2D a = new AffineModel2D();
    final int scale = 1 << scaleLevel;
    final double t = (scale - 1) * 0.5;
    a.set(scale, 0, 0, scale, t, t);
    return a;
}
Also used : AffineModel2D(mpicbg.models.AffineModel2D) Point(mpicbg.models.Point)

Example 7 with AffineModel2D

use of mpicbg.models.AffineModel2D 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 8 with AffineModel2D

use of mpicbg.models.AffineModel2D 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 9 with AffineModel2D

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

the class TransformMeshMappingWithMasks method map.

public final void map(final ImageProcessorWithMasks source, final ImageProcessorWithMasks target, final int numThreads) {
    target.outside = new ByteProcessor(target.getWidth(), target.getHeight());
    final HashMap<AffineModel2D, ArrayList<PointMatch>> av = transform.getAV();
    if (numThreads > 1) {
        final ArrayList<AffineModel2D> triangles = new ArrayList<AffineModel2D>(av.keySet());
        final AtomicInteger i = new AtomicInteger(0);
        final ArrayList<Thread> threads = new ArrayList<Thread>(numThreads);
        for (int k = 0; k < numThreads; ++k) {
            final Thread mtt = new MapTriangleThread(i, triangles, transform, source, target);
            threads.add(mtt);
            mtt.start();
        }
        for (final Thread mtt : threads) {
            try {
                mtt.join();
            } catch (final InterruptedException e) {
            }
        }
    } else if (source.mask == null) {
        for (final AffineModel2D triangle : av.keySet()) {
            mapTriangle(transform, triangle, source.ip, target.ip, target.outside);
        }
    } else {
        for (final AffineModel2D triangle : av.keySet()) {
            mapTriangle(transform, triangle, source.ip, source.mask, target.ip, target.mask, target.outside);
        }
    }
}
Also used : ByteProcessor(ij.process.ByteProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AffineModel2D(mpicbg.models.AffineModel2D) ArrayList(java.util.ArrayList)

Example 10 with AffineModel2D

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

the class TransformMeshMappingWithMasks method mapInterpolated.

public final void mapInterpolated(final ImageProcessorWithMasks source, final ImageProcessorWithMasks target, final int numThreads) {
    target.outside = new ByteProcessor(target.getWidth(), target.getHeight());
    source.ip.setInterpolationMethod(ImageProcessor.BILINEAR);
    if (source.mask != null) {
        source.mask.setInterpolationMethod(ImageProcessor.BILINEAR);
    }
    final HashMap<AffineModel2D, ArrayList<PointMatch>> av = transform.getAV();
    if (numThreads > 1) {
        final ArrayList<AffineModel2D> triangles = new ArrayList<AffineModel2D>(av.keySet());
        final AtomicInteger i = new AtomicInteger(0);
        final ArrayList<Thread> threads = new ArrayList<Thread>(numThreads);
        for (int k = 0; k < numThreads; ++k) {
            final Thread mtt = new MapTriangleInterpolatedThread(i, triangles, transform, source, target);
            threads.add(mtt);
            mtt.start();
        }
        for (final Thread mtt : threads) {
            try {
                mtt.join();
            } catch (final InterruptedException e) {
            }
        }
    } else if (source.mask == null) {
        for (final AffineModel2D triangle : av.keySet()) {
            mapTriangleInterpolated(transform, triangle, source.ip, target.ip, target.outside);
        }
    } else {
        for (final AffineModel2D triangle : av.keySet()) {
            mapTriangleInterpolated(transform, triangle, source.ip, source.mask, target.ip, target.mask, target.outside);
        }
    }
}
Also used : ByteProcessor(ij.process.ByteProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AffineModel2D(mpicbg.models.AffineModel2D) ArrayList(java.util.ArrayList)

Aggregations

AffineModel2D (mpicbg.models.AffineModel2D)27 ArrayList (java.util.ArrayList)18 PointMatch (mpicbg.models.PointMatch)15 SimilarityModel2D (mpicbg.models.SimilarityModel2D)15 NotEnoughDataPointsException (mpicbg.models.NotEnoughDataPointsException)12 Point (mpicbg.models.Point)12 AbstractAffineModel2D (mpicbg.models.AbstractAffineModel2D)11 RigidModel2D (mpicbg.models.RigidModel2D)9 TranslationModel2D (mpicbg.models.TranslationModel2D)9 Patch (ini.trakem2.display.Patch)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Layer (ini.trakem2.display.Layer)7 Rectangle (java.awt.Rectangle)7 AffineTransform (java.awt.geom.AffineTransform)7 RigidModel2D (mpicbg.trakem2.transform.RigidModel2D)6 TranslationModel2D (mpicbg.trakem2.transform.TranslationModel2D)6 SIFT (mpicbg.ij.SIFT)5 Feature (mpicbg.imagefeatures.Feature)5 FloatArray2DSIFT (mpicbg.imagefeatures.FloatArray2DSIFT)5 ByteProcessor (ij.process.ByteProcessor)4