Search in sources :

Example 6 with RandomAccessible

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

the class InvertAxisViewTest method defaultInvertAxisTest.

@Test
public void defaultInvertAxisTest() {
    final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    final MixedTransformView<DoubleType> il2 = Views.invertAxis((RandomAccessible<DoubleType>) img, 1);
    final MixedTransformView<DoubleType> opr = ops.transform().invertAxisView(deinterval(img), 1);
    for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) {
        for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) {
            assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j], 1e-10);
        }
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 7 with RandomAccessible

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

the class PermuteViewTest method defaultPermuteTest.

@Test
public void defaultPermuteTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    MixedTransformView<DoubleType> il2 = Views.permute((RandomAccessible<DoubleType>) img, 1, 0);
    MixedTransformView<DoubleType> opr = ops.transform().permuteView(deinterval(img), 1, 0);
    for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) {
        for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) {
            assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j], 1e-10);
        }
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 8 with RandomAccessible

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

the class RotateViewTest method testDefaultRotate.

@Test
public void testDefaultRotate() {
    final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 20, 10 }, new DoubleType());
    final MixedTransformView<DoubleType> il2 = Views.rotate((RandomAccessible<DoubleType>) img, 1, 0);
    final MixedTransformView<DoubleType> opr = ops.transform().rotateView(deinterval(img), 1, 0);
    for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) {
        for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) {
            assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j], 1e-10);
        }
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 9 with RandomAccessible

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

the class SubsampleViewTest method defaultSubsampleStepsTest.

@Test
public void defaultSubsampleStepsTest() {
    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, 1);
    SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2, 1);
    Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 9 }).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)

Example 10 with RandomAccessible

use of net.imglib2.RandomAccessible 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)

Aggregations

AbstractOpTest (net.imagej.ops.AbstractOpTest)12 DoubleType (net.imglib2.type.numeric.real.DoubleType)12 Test (org.junit.Test)12 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)5 ArrayList (java.util.ArrayList)3 Interval (net.imglib2.Interval)3 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)3 Random (java.util.Random)2 Ops (net.imagej.ops.Ops)2 FinalInterval (net.imglib2.FinalInterval)2 Point (net.imglib2.Point)2 RandomAccess (net.imglib2.RandomAccess)2 RandomAccessible (net.imglib2.RandomAccessible)2 DiamondShape (net.imglib2.algorithm.neighborhood.DiamondShape)2 Neighborhood (net.imglib2.algorithm.neighborhood.Neighborhood)2 Shape (net.imglib2.algorithm.neighborhood.Shape)2 LabelingType (net.imglib2.roi.labeling.LabelingType)2 BitType (net.imglib2.type.logic.BitType)2 IntType (net.imglib2.type.numeric.integer.IntType)2 FloatType (net.imglib2.type.numeric.real.FloatType)2