Search in sources :

Example 6 with Point

use of net.imglib2.Point in project imagej-ops by imagej.

the class PolygonFeatureTests method contour.

@Test
public void contour() {
    // ground truth computed with matlab
    final Polygon2D test = (Polygon2D) ops.run(DefaultContour.class, ROI, true);
    final List<? extends RealLocalizable> expected = GeomUtils.vertices(contour);
    final List<? extends RealLocalizable> received = GeomUtils.vertices(test);
    assertEquals("Number of polygon points differs.", expected.size(), received.size());
    for (int i = 0; i < contour.numVertices(); i++) {
        assertEquals("Polygon point " + i + " differs in x-coordinate.", expected.get(i).getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON);
        assertEquals("Polygon point " + i + " differs in y-coordinate.", expected.get(i).getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON);
    }
}
Also used : DefaultContour(net.imagej.ops.geom.geom2d.DefaultContour) Polygon2D(net.imglib2.roi.geom.real.Polygon2D) RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Example 7 with Point

use of net.imglib2.Point in project imagej-ops by imagej.

the class QuickHull3DTest method randomPointSet.

/**
 * Creates a random point cloud.
 *
 * @param n number of points
 * @param seed the seed
 * @return random point cloud
 */
private LinkedHashSet<RealLocalizable> randomPointSet(int n, long seed) {
    LinkedHashSet<RealLocalizable> points = new LinkedHashSet<>();
    Random r = new Random(seed);
    for (int i = 0; i < n; i++) {
        points.add(new Vertex(r.nextDouble(), r.nextDouble(), r.nextDouble()));
    }
    return points;
}
Also used : RealLocalizable(net.imglib2.RealLocalizable) LinkedHashSet(java.util.LinkedHashSet) Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) Random(java.util.Random)

Example 8 with Point

use of net.imglib2.Point in project imagej-ops by imagej.

the class ConvolveTest method placeSphereInCenter.

// utility to place a small sphere at the center of the image
private void placeSphereInCenter(Img<FloatType> img) {
    final Point center = new Point(img.numDimensions());
    for (int d = 0; d < img.numDimensions(); d++) center.setPosition(img.dimension(d) / 2, d);
    HyperSphere<FloatType> hyperSphere = new HyperSphere<>(img, center, 2);
    for (final FloatType value : hyperSphere) {
        value.setReal(1);
    }
}
Also used : HyperSphere(net.imglib2.algorithm.region.hypersphere.HyperSphere) Point(net.imglib2.Point) Point(net.imglib2.Point) FloatType(net.imglib2.type.numeric.real.FloatType) ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType)

Example 9 with Point

use of net.imglib2.Point in project imagej-ops by imagej.

the class ColocalisationTest method gaussianSmooth.

/**
 * Gaussian Smooth of the input image using intermediate float format.
 *
 * @param <T>
 * @param img
 * @param sigma
 * @return
 */
public static <T extends RealType<T> & NativeType<T>> Img<T> gaussianSmooth(RandomAccessibleInterval<T> img, double[] sigma) {
    Interval interval = Views.iterable(img);
    ImgFactory<T> outputFactory = new ArrayImgFactory<T>();
    final long[] dim = new long[img.numDimensions()];
    img.dimensions(dim);
    Img<T> output = outputFactory.create(dim, img.randomAccess().get().createVariable());
    final long[] pos = new long[img.numDimensions()];
    Arrays.fill(pos, 0);
    Localizable origin = new Point(pos);
    ImgFactory<FloatType> tempFactory = new ArrayImgFactory<FloatType>();
    RandomAccessible<T> input = Views.extendMirrorSingle(img);
    Gauss.inFloat(sigma, input, interval, output, origin, tempFactory);
    return output;
}
Also used : Point(net.imglib2.Point) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) Localizable(net.imglib2.Localizable) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Interval(net.imglib2.Interval) FloatType(net.imglib2.type.numeric.real.FloatType)

Example 10 with Point

use of net.imglib2.Point in project imagej-ops by imagej.

the class BoxCount method calculate.

/**
 * Counts the number of foreground sections in the interval repeatedly with
 * different size sections
 *
 * @param input an n-dimensional binary interval
 * @return A list of (log(foreground count), -log(section size))
 *         {@link ValuePair} objects for curve fitting
 */
@Override
public List<ValuePair<DoubleType, DoubleType>> calculate(final RandomAccessibleInterval<B> input) {
    final List<ValuePair<DoubleType, DoubleType>> points = new ArrayList<>();
    final int dimensions = input.numDimensions();
    final long[] sizes = new long[dimensions];
    final long numTranslations = 1 + gridMoves;
    input.dimensions(sizes);
    for (long sectionSize = maxSize; sectionSize >= minSize; sectionSize /= scaling) {
        final long translationAmount = Math.max(1, sectionSize / numTranslations);
        final Stream<long[]> translations = translationStream(numTranslations, translationAmount, dimensions - 1, new long[dimensions]);
        final LongStream foregroundCounts = countTranslatedGrids(input, translations, sizes, sectionSize);
        final long foreground = foregroundCounts.min().orElse(0);
        final double logSize = -Math.log(sectionSize);
        final double logCount = Math.log(foreground);
        final ValuePair<DoubleType, DoubleType> point = new ValuePair<>(new DoubleType(logSize), new DoubleType(logCount));
        points.add(point);
    }
    return points;
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) ValuePair(net.imglib2.util.ValuePair) ArrayList(java.util.ArrayList) LongStream(java.util.stream.LongStream)

Aggregations

ArrayList (java.util.ArrayList)10 RealPoint (net.imglib2.RealPoint)10 Point (net.imglib2.Point)8 Test (org.junit.Test)7 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)5 DoubleType (net.imglib2.type.numeric.real.DoubleType)5 Point (com.google.monitoring.v3.Point)4 AbstractFeatureTest (net.imagej.ops.features.AbstractFeatureTest)4 HyperSphere (net.imglib2.algorithm.region.hypersphere.HyperSphere)4 Polygon2D (net.imglib2.roi.geom.real.Polygon2D)4 FloatType (net.imglib2.type.numeric.real.FloatType)4 Metric (com.google.api.Metric)3 TimeInterval (com.google.monitoring.v3.TimeInterval)3 TimeSeries (com.google.monitoring.v3.TimeSeries)3 TypedValue (com.google.monitoring.v3.TypedValue)3 List (java.util.List)3 Interval (net.imglib2.Interval)3 MonitoredResource (com.google.api.MonitoredResource)2 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)2 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)2