Search in sources :

Example 26 with Pair

use of net.imglib2.util.Pair in project imagej-ops by imagej.

the class DefaultMinorMajorAxis method calculate.

@Override
public Pair<DoubleType, DoubleType> calculate(final Polygon2D input) {
    List<RealLocalizable> points = new ArrayList<>(GeomUtils.vertices(input));
    // Sort RealLocalizables of P by x-coordinate (in case of a tie,
    // sort by
    // y-coordinate). Sorting is counter clockwise.
    Collections.sort(points, new Comparator<RealLocalizable>() {

        @Override
        public int compare(final RealLocalizable o1, final RealLocalizable o2) {
            final Double o1x = new Double(o1.getDoublePosition(0));
            final Double o2x = new Double(o2.getDoublePosition(0));
            final int result = o2x.compareTo(o1x);
            if (result == 0) {
                return new Double(o2.getDoublePosition(1)).compareTo(new Double(o1.getDoublePosition(1)));
            }
            return result;
        }
    });
    points.add(points.get(0));
    // calculate minor and major axis
    double[] minorMajorAxis = getMinorMajorAxis(input, points);
    return new ValuePair<>(new DoubleType(minorMajorAxis[0]), new DoubleType(minorMajorAxis[1]));
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) DoubleType(net.imglib2.type.numeric.real.DoubleType) ValuePair(net.imglib2.util.ValuePair) ArrayList(java.util.ArrayList)

Example 27 with Pair

use of net.imglib2.util.Pair in project imagej-ops by imagej.

the class DefaultFeretsAngle method compute.

@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {
    final RealLocalizable p1 = input.getA();
    final RealLocalizable p2 = input.getB();
    final double degree = Math.atan2(p2.getDoublePosition(1) - p1.getDoublePosition(1), p2.getDoublePosition(0) - p1.getDoublePosition(0)) * (180.0 / Math.PI);
    output.set(degree % 180);
}
Also used : RealLocalizable(net.imglib2.RealLocalizable)

Example 28 with Pair

use of net.imglib2.util.Pair in project imagej-ops by imagej.

the class DefaultFeretsDiameter method compute.

@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {
    final RealLocalizable p1 = input.getA();
    final RealLocalizable p2 = input.getB();
    output.set(Math.hypot(p1.getDoublePosition(0) - p2.getDoublePosition(0), p1.getDoublePosition(1) - p2.getDoublePosition(1)));
}
Also used : RealLocalizable(net.imglib2.RealLocalizable)

Example 29 with Pair

use of net.imglib2.util.Pair in project imagej-ops by imagej.

the class DefaultMaximumFeret method calculate.

@Override
public Pair<RealLocalizable, RealLocalizable> calculate(Polygon2D input) {
    final List<? extends RealLocalizable> points = GeomUtils.vertices(function.calculate(input));
    double distance = Double.NEGATIVE_INFINITY;
    RealLocalizable p0 = points.get(0);
    RealLocalizable p1 = points.get(0);
    for (int i = 0; i < points.size(); i++) {
        for (int j = i + 2; j < points.size(); j++) {
            final RealLocalizable tmpP0 = points.get(i);
            final RealLocalizable tmpP1 = points.get(j);
            final double tmp = Math.sqrt(Math.pow(tmpP0.getDoublePosition(0) - tmpP1.getDoublePosition(0), 2) + Math.pow(tmpP0.getDoublePosition(1) - tmpP1.getDoublePosition(1), 2));
            if (tmp > distance) {
                distance = tmp;
                p0 = tmpP0;
                p1 = tmpP1;
            }
        }
    }
    return new ValuePair<>(p0, p1);
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) ValuePair(net.imglib2.util.ValuePair)

Example 30 with Pair

use of net.imglib2.util.Pair in project imagej-ops by imagej.

the class NormalizeTest method testNormalize.

@Test
public void testNormalize() {
    Img<ByteType> in = generateByteArrayTestImg(true, 5, 5);
    Img<ByteType> out = in.factory().create(in, new ByteType());
    ops.run(NormalizeIIComputer.class, out, in);
    final Pair<ByteType, ByteType> minMax2 = ops.stats().minMax(out);
    assertEquals(minMax2.getA().get(), Byte.MIN_VALUE);
    assertEquals(minMax2.getB().get(), Byte.MAX_VALUE);
    final IterableInterval<ByteType> lazyOut = ops.image().normalize(in);
    final IterableInterval<ByteType> notLazyOut = ops.image().normalize(in, null, null, null, null, false);
    final Cursor<ByteType> outCursor = out.cursor();
    final Cursor<ByteType> lazyCursor = lazyOut.cursor();
    final Cursor<ByteType> notLazyCursor = notLazyOut.cursor();
    while (outCursor.hasNext()) {
        assertEquals(outCursor.next().get(), lazyCursor.next().get());
        assertEquals(outCursor.get().get(), notLazyCursor.next().get());
    }
}
Also used : ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

Pair (android.support.v4.util.Pair)75 ArrayList (java.util.ArrayList)37 View (android.view.View)26 Pair (org.apache.commons.math3.util.Pair)25 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)16 Intent (android.content.Intent)15 TextView (android.widget.TextView)14 List (java.util.List)12 ImageView (android.widget.ImageView)10 RecyclerView (android.support.v7.widget.RecyclerView)8 AlertDialog (android.support.v7.app.AlertDialog)7 ByteProcessor (ij.process.ByteProcessor)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Pair (mpicbg.trakem2.util.Pair)7 NonNull (android.support.annotation.NonNull)6 OsmandSettings (net.osmand.plus.OsmandSettings)6 DialogInterface (android.content.DialogInterface)5 Transition (android.transition.Transition)4 RealLocalizable (net.imglib2.RealLocalizable)4