Search in sources :

Example 11 with Point

use of com.google.monitoring.v3.Point in project imagej-ops by imagej.

the class NonCirculantNormalizationFactor method createNormalizationImageSemiNonCirculant.

protected void createNormalizationImageSemiNonCirculant() {
    // k is the window size (valid image region)
    final int length = k.numDimensions();
    final long[] n = new long[length];
    final long[] nFFT = new long[length];
    // also referred to as object space size
    for (int d = 0; d < length; d++) {
        n[d] = k.dimension(d) + l.dimension(d) - 1;
    }
    for (int d = 0; d < length; d++) {
        nFFT[d] = imgConvolutionInterval.dimension(d);
    }
    FinalDimensions fd = new FinalDimensions(nFFT);
    // create the normalization image
    normalization = create.calculate(fd);
    // size of the measurement window
    final Point size = new Point(length);
    final long[] sizel = new long[length];
    for (int d = 0; d < length; d++) {
        size.setPosition(k.dimension(d), d);
        sizel[d] = k.dimension(d);
    }
    // starting point of the measurement window when it is centered in fft space
    final Point start = new Point(length);
    final long[] startl = new long[length];
    final long[] endl = new long[length];
    for (int d = 0; d < length; d++) {
        start.setPosition((nFFT[d] - k.dimension(d)) / 2, d);
        startl[d] = (nFFT[d] - k.dimension(d)) / 2;
        endl[d] = startl[d] + sizel[d] - 1;
    }
    // size of the object space
    final Point maskSize = new Point(length);
    final long[] maskSizel = new long[length];
    for (int d = 0; d < length; d++) {
        maskSize.setPosition(Math.min(n[d], nFFT[d]), d);
        maskSizel[d] = Math.min(n[d], nFFT[d]);
    }
    // starting point of the object space within the fft space
    final Point maskStart = new Point(length);
    final long[] maskStartl = new long[length];
    for (int d = 0; d < length; d++) {
        maskStart.setPosition((Math.max(0, nFFT[d] - n[d]) / 2), d);
        maskStartl[d] = (Math.max(0, nFFT[d] - n[d]) / 2);
    }
    final RandomAccessibleInterval<O> temp = Views.interval(normalization, new FinalInterval(startl, endl));
    final Cursor<O> normCursor = Views.iterable(temp).cursor();
    // draw a cube the size of the measurement space
    while (normCursor.hasNext()) {
        normCursor.fwd();
        normCursor.get().setReal(1.0);
    }
    final Img<O> tempImg = create.calculate(fd);
    // 3. correlate psf with the output of step 2.
    correlater.compute(normalization, tempImg);
    normalization = tempImg;
    final Cursor<O> cursorN = normalization.cursor();
    while (cursorN.hasNext()) {
        cursorN.fwd();
        if (cursorN.get().getRealFloat() <= 1e-3f) {
            cursorN.get().setReal(1.0f);
        }
    }
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) FinalInterval(net.imglib2.FinalInterval) Point(net.imglib2.Point) Point(net.imglib2.Point)

Example 12 with Point

use of com.google.monitoring.v3.Point in project imagej-ops by imagej.

the class FFTTest method placeSphereInCenter.

/**
 * utility that places a sphere in the center of the image
 *
 * @param img
 */
private void placeSphereInCenter(final 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);
    final 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 13 with Point

use of com.google.monitoring.v3.Point in project imagej-ops by imagej.

the class ConvolveTest method testCreateAndConvolvePoints.

/**
 * tests fft based convolve
 */
@Test
public void testCreateAndConvolvePoints() {
    final int xSize = 128;
    final int ySize = 128;
    final int zSize = 128;
    int[] size = new int[] { xSize, ySize, zSize };
    Img<DoubleType> phantom = ops.create().img(size);
    RandomAccess<DoubleType> randomAccess = phantom.randomAccess();
    randomAccess.setPosition(new long[] { xSize / 2, ySize / 2, zSize / 2 });
    randomAccess.get().setReal(255.0);
    randomAccess.setPosition(new long[] { xSize / 4, ySize / 4, zSize / 4 });
    randomAccess.get().setReal(255.0);
    Point location = new Point(phantom.numDimensions());
    location.setPosition(new long[] { 3 * xSize / 4, 3 * ySize / 4, 3 * zSize / 4 });
    HyperSphere<DoubleType> hyperSphere = new HyperSphere<>(phantom, location, 5);
    for (DoubleType value : hyperSphere) {
        value.setReal(16);
    }
    // create psf using the gaussian kernel op (alternatively PSF could be an
    // input to the script)
    RandomAccessibleInterval<DoubleType> psf = ops.create().kernelGauss(new double[] { 5, 5, 5 }, new DoubleType());
    // convolve psf with phantom
    RandomAccessibleInterval<DoubleType> convolved = ops.filter().convolve(phantom, psf);
    DoubleType sum = new DoubleType();
    DoubleType max = new DoubleType();
    DoubleType min = new DoubleType();
    ops.stats().sum(sum, Views.iterable(convolved));
    ops.stats().max(max, Views.iterable(convolved));
    ops.stats().min(min, Views.iterable(convolved));
    assertEquals(sum.getRealDouble(), 8750.00, 0.001);
    assertEquals(max.getRealDouble(), 3.155, 0.001);
    assertEquals(min.getRealDouble(), 2.978E-7, 0.001);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) HyperSphere(net.imglib2.algorithm.region.hypersphere.HyperSphere) Point(net.imglib2.Point) Point(net.imglib2.Point) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 14 with Point

use of com.google.monitoring.v3.Point in project imagej-ops by imagej.

the class DeconvolveTest 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)

Aggregations

Point (net.imglib2.Point)8 Point (com.google.monitoring.v3.Point)4 HyperSphere (net.imglib2.algorithm.region.hypersphere.HyperSphere)4 FloatType (net.imglib2.type.numeric.real.FloatType)4 Metric (com.google.api.Metric)3 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)3 TimeInterval (com.google.monitoring.v3.TimeInterval)3 TimeSeries (com.google.monitoring.v3.TimeSeries)3 TypedValue (com.google.monitoring.v3.TypedValue)3 ArrayList (java.util.ArrayList)3 MonitoredResource (com.google.api.MonitoredResource)2 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)2 ProjectName (com.google.monitoring.v3.ProjectName)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Interval (net.imglib2.Interval)2 Collections2 (com.google.common.collect.Collections2)1