Search in sources :

Example 1 with Point

use of net.imglib2.Point in project vcell by virtualcell.

the class DeconstructGeometryCommand method run.

@Override
public void run() {
    // Crop to get a z-stack over time (remove channel dimension)
    long maxX = fluorData.max(fluorData.dimensionIndex(Axes.X));
    long maxY = fluorData.max(fluorData.dimensionIndex(Axes.Y));
    long maxZ = fluorData.max(fluorData.dimensionIndex(Axes.Z));
    long maxTime = fluorData.max(fluorData.dimensionIndex(Axes.TIME));
    Img fluorImg = fluorData.getImgPlus().getImg();
    FinalInterval intervals = Intervals.createMinMax(0, 0, 0, 0, 0, maxX, maxY, maxZ, 0, maxTime);
    RandomAccessibleInterval fluorImgCropped = ops.transform().crop(fluorImg, intervals, true);
    // Calculate scale factors
    double[] scaleFactors = { 1, 1, 1, 1 };
    for (int i = 0; i < geomData.numDimensions(); i++) {
        scaleFactors[i] = geomData.dimension(i) / (double) fluorImgCropped.dimension(i);
    }
    // Scale the fluorescence dataset to match the geometry
    NLinearInterpolatorFactory interpolatorFactory = new NLinearInterpolatorFactory();
    RandomAccessibleInterval fluorScaled = ops.transform().scale(fluorImgCropped, scaleFactors, interpolatorFactory);
    // Crop out the first slice of each z-stack in time series
    intervals = Intervals.createMinMax(0, 0, 0, 0, fluorScaled.dimension(0) - 1, fluorScaled.dimension(1) - 1, 0, fluorScaled.dimension(3) - 1);
    IntervalView fluorXYT = (IntervalView) ops.transform().crop(fluorScaled, intervals, true);
    // Create a blank image of the same X-Y-Time dimensions
    long[] dimensions = { fluorXYT.dimension(0), fluorXYT.dimension(1), fluorXYT.dimension(2) };
    Img<DoubleType> result = ops.create().img(dimensions);
    // Calculate constant d in TIRF exponential decay function
    theta = theta * 2 * Math.PI / 360;
    double n1 = 1.52;
    double n2 = 1.38;
    double d = lambda * Math.pow((Math.pow(n1, 2) * Math.pow(Math.sin(theta), 2) - Math.pow(n2, 2)), -0.5) / (4 * Math.PI);
    // Iterate through each time point, using 3D geometry to generate 2D intensities
    Cursor<DoubleType> cursor = fluorXYT.localizingCursor();
    RandomAccess fluorRA = fluorScaled.randomAccess();
    RandomAccess<RealType<?>> geomRA = geomData.randomAccess();
    RandomAccess<DoubleType> resultRA = result.randomAccess();
    maxZ = geomData.dimension(2) - 1;
    while (cursor.hasNext()) {
        cursor.fwd();
        int[] positionXYZ = { cursor.getIntPosition(0), cursor.getIntPosition(1), (int) maxZ - 1 };
        int[] positionXYZT = { cursor.getIntPosition(0), cursor.getIntPosition(1), (int) maxZ - 1, cursor.getIntPosition(2) };
        resultRA.setPosition(cursor);
        geomRA.setPosition(positionXYZ);
        double sum = 0.0;
        while (positionXYZ[2] >= 0 && geomRA.get().getRealDouble() != 0.0) {
            fluorRA.setPosition(positionXYZT);
            geomRA.setPosition(positionXYZ);
            sum += geomRA.get().getRealDouble() * Math.exp(-zSpacing * positionXYZ[2] / d);
            positionXYZ[2]--;
        }
        resultRA.get().set(sum);
    }
    System.out.println("done");
    displayService.createDisplay(result);
}
Also used : Img(net.imglib2.img.Img) NLinearInterpolatorFactory(net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory) RandomAccess(net.imglib2.RandomAccess) RealType(net.imglib2.type.numeric.RealType) IntervalView(net.imglib2.view.IntervalView) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalInterval(net.imglib2.FinalInterval)

Example 2 with Point

use of net.imglib2.Point in project java-docs-samples by GoogleCloudPlatform.

the class TimeSeriesSummary method getMostRecentPoint.

Point getMostRecentPoint(TimeSeries timeSeries) {
    Point max = Collections.max(timeSeries.getPointsList(), Comparator.comparingLong(p -> p.getInterval().getEndTime().getSeconds()));
    mostRecentRunTime = max.getInterval().getEndTime();
    return max;
}
Also used : List(java.util.List) Lists(com.google.common.collect.Lists) TimeSeries(com.google.monitoring.v3.TimeSeries) Collections2(com.google.common.collect.Collections2) Point(com.google.monitoring.v3.Point) Comparator(java.util.Comparator) Timestamp(com.google.protobuf.Timestamp) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Point(com.google.monitoring.v3.Point)

Example 3 with Point

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

the class PolygonFeatureTests method labelRegionToPolygonConverter.

@Test
public void labelRegionToPolygonConverter() {
    // ground truth computed with matlab
    final LabelRegionToPolygonConverter c = new LabelRegionToPolygonConverter();
    c.setContext(ops.context());
    final Polygon2D test = c.convert(ROI, Polygon2D.class);
    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 : LabelRegionToPolygonConverter(net.imagej.ops.geom.geom2d.LabelRegionToPolygonConverter) Polygon2D(net.imglib2.roi.geom.real.Polygon2D) RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Example 4 with Point

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

the class PolygonFeatureTests method smallesEnclosingRectangle.

@Test
public void smallesEnclosingRectangle() {
    // ground truth verified with matlab
    final List<? extends RealLocalizable> received = GeomUtils.vertices(((Polygon2D) ops.run(DefaultSmallestEnclosingRectangle.class, contour)));
    final RealPoint[] expected = new RealPoint[] { new RealPoint(37.229184188393, -0.006307821699), new RealPoint(-14.757779646762, 27.800672834315), new RealPoint(31.725820016821, 114.704793944491), new RealPoint(83.712783851976, 86.897813288478) };
    assertEquals("Number of polygon points differs.", expected.length, received.size());
    for (int i = 0; i < expected.length; i++) {
        assertEquals("Polygon point " + i + " differs in x-coordinate.", expected[i].getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON);
        assertEquals("Polygon point " + i + " differs in y-coordinate.", expected[i].getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON);
    }
}
Also used : RealPoint(net.imglib2.RealPoint) Polygon2D(net.imglib2.roi.geom.real.Polygon2D) DefaultSmallestEnclosingRectangle(net.imagej.ops.geom.geom2d.DefaultSmallestEnclosingRectangle) RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Example 5 with Point

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

the class PolygonFeatureTests method convexHull2D.

@Test
public void convexHull2D() {
    // ground truth computed with matlab
    final Polygon2D test = (Polygon2D) ops.run(DefaultConvexHull2D.class, contour);
    final List<? extends RealLocalizable> received = GeomUtils.vertices(test);
    final RealPoint[] expected = new RealPoint[] { new RealPoint(1, 30), new RealPoint(2, 29), new RealPoint(26, 6), new RealPoint(31, 6), new RealPoint(42, 9), new RealPoint(49, 22), new RealPoint(72, 65), new RealPoint(78, 77), new RealPoint(48, 106), new RealPoint(42, 109), new RealPoint(34, 109), new RealPoint(28, 106), new RealPoint(26, 104), new RealPoint(23, 98) };
    assertEquals("Number of polygon points differs.", expected.length, received.size());
    for (int i = 0; i < expected.length; i++) {
        assertEquals("Polygon point " + i + " differs in x-coordinate.", expected[i].getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON);
        assertEquals("Polygon point " + i + " differs in y-coordinate.", expected[i].getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON);
    }
}
Also used : RealPoint(net.imglib2.RealPoint) DefaultConvexHull2D(net.imagej.ops.geom.geom2d.DefaultConvexHull2D) Polygon2D(net.imglib2.roi.geom.real.Polygon2D) RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

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