use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class CreateImgTest method testImageType.
@Test
public void testImageType() {
final Dimensions dim = new FinalDimensions(10, 10, 10);
assertEquals("Image Type: ", BitType.class, ((Img<?>) ops.run(CreateImgFromDimsAndType.class, dim, new BitType())).firstElement().getClass());
assertEquals("Image Type: ", ByteType.class, ((Img<?>) ops.run(CreateImgFromDimsAndType.class, dim, new ByteType())).firstElement().getClass());
assertEquals("Image Type: ", UnsignedByteType.class, ((Img<?>) ops.create().img(dim, new UnsignedByteType())).firstElement().getClass());
assertEquals("Image Type: ", IntType.class, ((Img<?>) ops.run(CreateImgFromDimsAndType.class, dim, new IntType())).firstElement().getClass());
assertEquals("Image Type: ", FloatType.class, ((Img<?>) ops.run(CreateImgFromDimsAndType.class, dim, new FloatType())).firstElement().getClass());
assertEquals("Image Type: ", DoubleType.class, ((Img<?>) ops.run(CreateImgFromDimsAndType.class, dim, new DoubleType())).firstElement().getClass());
}
use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class CreateImgTest method testImgFromImg.
@Test
public void testImgFromImg() {
// create img
final Img<ByteType> img = ops.create().img(new FinalDimensions(1), new ByteType());
@SuppressWarnings("unchecked") final Img<ByteType> newImg = (Img<ByteType>) ops.run(CreateImgFromImg.class, img);
// should both be ByteType. New Img shouldn't be DoubleType (default)
assertEquals(img.firstElement().getClass(), newImg.firstElement().getClass());
}
use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class CreateLabelingTest method testImageFactory.
@SuppressWarnings("unchecked")
@Test
public void testImageFactory() {
final Dimensions dim = new FinalDimensions(10, 10, 10);
assertEquals("Labeling Factory: ", ArrayImgFactory.class, ((Img<?>) ((ImgLabeling<String, ?>) ops.run(DefaultCreateImgLabeling.class, dim, null, new ArrayImgFactory<IntType>())).getIndexImg()).factory().getClass());
assertEquals("Labeling Factory: ", CellImgFactory.class, ((Img<?>) ((ImgLabeling<String, ?>) ops.run(DefaultCreateImgLabeling.class, dim, null, new CellImgFactory<IntType>())).getIndexImg()).factory().getClass());
}
use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class CopyRAITest method createData.
@Before
public void createData() {
input = new ArrayImgFactory<UnsignedByteType>().create(new int[] { 120, 100 }, new UnsignedByteType());
final Random r = new Random(System.currentTimeMillis());
final Cursor<UnsignedByteType> inc = input.cursor();
while (inc.hasNext()) {
inc.next().setReal(r.nextDouble() * 255);
}
// create
final long[] start = new long[] { 16, 16, 16 };
final long[] end = new long[] { 47, 47, 47 };
// create an input with a cube at the center
input2 = ops.create().img(new FinalDimensions(size1), new UnsignedByteType());
// create the same input but force it to be a planar image
inputPlanar = ops.create().img(new FinalDimensions(size1), new UnsignedByteType(), new PlanarImgFactory<UnsignedByteType>());
// get centered views
view = Views.interval(input2, new FinalInterval(start, end));
viewPlanar = Views.interval(inputPlanar, new FinalInterval(start, end));
final Cursor<UnsignedByteType> cursor = view.cursor();
final Cursor<UnsignedByteType> cursorPlanar = viewPlanar.cursor();
// set every pixel in the view to 100
while (cursor.hasNext()) {
cursor.fwd();
cursorPlanar.fwd();
cursor.get().setReal(100.0);
cursorPlanar.get().setReal(100.0);
}
}
use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class CopyRAITest method copyRAIDifferentSizeTest.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void copyRAIDifferentSizeTest() {
// create a copy op
final UnaryHybridCF<IntervalView<UnsignedByteType>, RandomAccessibleInterval<UnsignedByteType>> copy = (UnaryHybridCF) Hybrids.unaryCF(ops, CopyRAI.class, RandomAccessibleInterval.class, IntervalView.class);
assertNotNull(copy);
final Img<UnsignedByteType> out = ops.create().img(new FinalDimensions(size2), new UnsignedByteType());
// copy view to output and assert that is equal to the mean of the view
copy.compute(view, out);
assertEquals(ops.stats().mean(out).getRealDouble(), 100.0, delta);
// also try with a planar image
final Img<UnsignedByteType> outFromPlanar = ops.create().img(new FinalDimensions(size2), new UnsignedByteType());
copy.compute(viewPlanar, outFromPlanar);
assertEquals(ops.stats().mean(outFromPlanar).getRealDouble(), 100.0, delta);
}
Aggregations