Search in sources :

Example 41 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class UnaryRealTypeMathTest method assertRandomUniform.

private void assertRandomUniform(final double i, final double o, final double i2, final double o2) {
    final DoubleType in = new DoubleType(i);
    final DoubleType out = new DoubleType();
    final long seed = 0xcafebabe12345678L;
    @SuppressWarnings("unchecked") final UnaryRealTypeMath.RandomUniform<DoubleType, DoubleType> op = ops.op(UnaryRealTypeMath.RandomUniform.class, in.createVariable(), in, seed);
    op.compute(in, out);
    assertEquals(o, out.get(), 0);
    in.set(i2);
    op.compute(in, out);
    assertEquals(o2, out.get(), 0);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType)

Example 42 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType 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 43 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType 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 44 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType 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 45 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class DefaultFeretsDiameterForAngle method compute.

@Override
public void compute(Polygon2D input, DoubleType output) {
    final List<? extends RealLocalizable> points = GeomUtils.vertices(function.calculate(input));
    final double angleRad = -angle * Math.PI / 180.0;
    double minX = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    for (RealLocalizable p : points) {
        final double tmpX = p.getDoublePosition(0) * Math.cos(angleRad) - p.getDoublePosition(1) * Math.sin(angleRad);
        minX = tmpX < minX ? tmpX : minX;
        maxX = tmpX > maxX ? tmpX : maxX;
    }
    output.set(Math.abs(maxX - minX));
}
Also used : RealLocalizable(net.imglib2.RealLocalizable)

Aggregations

DoubleType (net.imglib2.type.numeric.real.DoubleType)185 Test (org.junit.Test)123 AbstractOpTest (net.imagej.ops.AbstractOpTest)111 LongType (net.imglib2.type.numeric.integer.LongType)37 MersenneTwisterFast (org.scijava.util.MersenneTwisterFast)19 ArrayList (java.util.ArrayList)14 Dataset (net.imagej.Dataset)14 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)13 Img (net.imglib2.img.Img)10 PointSet (net.imglib2.ops.pointset.PointSet)10 Ops (net.imagej.ops.Ops)9 HyperVolumePointSet (net.imglib2.ops.pointset.HyperVolumePointSet)9 Overlay (net.imagej.overlay.Overlay)8 FinalDimensions (net.imglib2.FinalDimensions)8 FinalInterval (net.imglib2.FinalInterval)8 BitType (net.imglib2.type.logic.BitType)8 DatasetView (net.imagej.display.DatasetView)7 Dimensions (net.imglib2.Dimensions)7 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)7 RealLocalizable (net.imglib2.RealLocalizable)6