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);
}
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]));
}
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)));
}
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);
}
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));
}
Aggregations