Search in sources :

Example 71 with Cursor

use of net.imglib2.Cursor 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 72 with Cursor

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

the class PermuteViewTest method permuteCoordinatesOfDimensionTest.

@Test
public void permuteCoordinatesOfDimensionTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
    Cursor<DoubleType> c = img.cursor();
    Random r = new Random();
    while (c.hasNext()) {
        c.next().set(r.nextDouble());
    }
    Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[] { 0, 1 }, 1).cursor();
    RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[] { 0, 1 }, 1).randomAccess();
    while (il2.hasNext()) {
        il2.next();
        opr.setPosition(il2);
        assertEquals(il2.get().get(), opr.get().get(), 1e-10);
    }
}
Also used : Random(java.util.Random) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 73 with Cursor

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

the class PermuteViewTest method defaultPermuteCoordinatesTest.

@Test
public void defaultPermuteCoordinatesTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
    Cursor<DoubleType> c = img.cursor();
    Random r = new Random();
    while (c.hasNext()) {
        c.next().set(r.nextDouble());
    }
    Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[] { 0, 1 }).cursor();
    RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[] { 0, 1 }).randomAccess();
    while (il2.hasNext()) {
        il2.next();
        opr.setPosition(il2);
        assertEquals(il2.get().get(), opr.get().get(), 1e-10);
    }
}
Also used : Random(java.util.Random) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 74 with Cursor

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

the class PermuteViewTest method defaultPermuteCoordinatesInverseTest.

@Test
public void defaultPermuteCoordinatesInverseTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
    Cursor<DoubleType> c = img.cursor();
    Random r = new Random();
    while (c.hasNext()) {
        c.next().set(r.nextDouble());
    }
    Cursor<DoubleType> il2 = Views.permuteCoordinatesInverse(img, new int[] { 0, 1 }).cursor();
    RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[] { 0, 1 }).randomAccess();
    while (il2.hasNext()) {
        il2.next();
        opr.setPosition(il2);
        assertEquals(il2.get().get(), opr.get().get(), 1e-10);
    }
}
Also used : Random(java.util.Random) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 75 with Cursor

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

the class SubsampleViewTest method defaultSubsampleTest.

@Test
public void defaultSubsampleTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    Random r = new Random();
    for (DoubleType d : img) {
        d.set(r.nextDouble());
    }
    SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2);
    SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2);
    Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 4 }).localizingCursor();
    RandomAccess<DoubleType> oprRA = opr.randomAccess();
    while (il2C.hasNext()) {
        il2C.next();
        oprRA.setPosition(il2C);
        assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
    }
}
Also used : Random(java.util.Random) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)43 AbstractOpTest (net.imagej.ops.AbstractOpTest)40 DoubleType (net.imglib2.type.numeric.real.DoubleType)30 Random (java.util.Random)21 FinalInterval (net.imglib2.FinalInterval)21 ByteType (net.imglib2.type.numeric.integer.ByteType)14 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)12 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)11 ArrayList (java.util.ArrayList)10 DiamondShape (net.imglib2.algorithm.neighborhood.DiamondShape)10 Shape (net.imglib2.algorithm.neighborhood.Shape)10 BitType (net.imglib2.type.logic.BitType)8 FloatType (net.imglib2.type.numeric.real.FloatType)8 Img (net.imglib2.img.Img)7 HorizontalLineShape (net.imglib2.algorithm.neighborhood.HorizontalLineShape)6 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)6 Before (org.junit.Before)6 IterableInterval (net.imglib2.IterableInterval)4 Point (net.imglib2.Point)4 RealPoint (net.imglib2.RealPoint)4