use of net.imglib2.img.array.ArrayImgFactory 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);
}
}
use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.
the class PermuteViewTest method testIntervalPermute.
@Test
public void testIntervalPermute() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
IntervalView<DoubleType> expected = Views.permute((RandomAccessibleInterval<DoubleType>) img, 1, 0);
IntervalView<DoubleType> actual = ops.transform().permuteView((RandomAccessibleInterval<DoubleType>) img, 1, 0);
for (int i = 0; i < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix().length; i++) {
for (int j = 0; j < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i].length; j++) {
assertEquals(((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i][j], ((MixedTransformView<DoubleType>) actual.getSource()).getTransformToSource().getMatrix()[i][j], 1e-10);
}
}
}
use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.
the class RotateViewTest method testIntervalRotateInterval.
@Test
public void testIntervalRotateInterval() {
final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 20, 10 }, new DoubleType());
final IntervalView<DoubleType> il2 = Views.rotate((RandomAccessibleInterval<DoubleType>) img, 1, 0);
final IntervalView<DoubleType> opr = ops.transform().rotateView((RandomAccessibleInterval<DoubleType>) img, 1, 0);
assertEquals(img.min(1), il2.min(0));
assertEquals(img.max(1), il2.max(0));
assertEquals(img.min(0), -il2.max(1));
assertEquals(img.max(0), -il2.min(1));
for (int i = 0; i < il2.numDimensions(); i++) {
assertEquals(il2.max(i), opr.max(i));
assertEquals(il2.min(i), opr.min(i));
}
}
use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.
the class StackViewTest method defaultStackTest.
@Test
public void defaultStackTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
List<Img<DoubleType>> list = new ArrayList<>();
list.add(img);
list.add(img);
RandomAccessibleInterval<DoubleType> il2 = Views.stack(list);
RandomAccessibleInterval<DoubleType> opr = ops.transform().stackView(list);
assertEquals(il2.dimension(2), opr.dimension(2));
}
use of net.imglib2.img.array.ArrayImgFactory 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);
}
}
Aggregations