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