use of net.imglib2.type.numeric.integer.UnsignedByteType 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.type.numeric.integer.UnsignedByteType in project imagej-ops by imagej.
the class AbstractOpTest method generateRandomlyFilledUnsignedByteTestImgWithSeed.
public Img<UnsignedByteType> generateRandomlyFilledUnsignedByteTestImgWithSeed(final long[] dims, final long tempSeed) {
final Img<UnsignedByteType> img = ArrayImgs.unsignedBytes(dims);
final Random rand = new Random(tempSeed);
final Cursor<UnsignedByteType> cursor = img.cursor();
while (cursor.hasNext()) {
cursor.next().set(rand.nextInt((int) img.firstElement().getMaxValue()));
}
return img;
}
use of net.imglib2.type.numeric.integer.UnsignedByteType 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.type.numeric.integer.UnsignedByteType 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);
}
use of net.imglib2.type.numeric.integer.UnsignedByteType in project TrakEM2 by trakem2.
the class LinearIntensityMap method main.
public static void main(final String[] args) {
new ImageJ();
final double[] coefficients = new double[] { 0, 2, 4, 8, 1, 1, 1, 1, 1, 10, 5, 1, 1, 1, 1, 1, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150 };
final LinearIntensityMap<DoubleType> transform = new LinearIntensityMap<DoubleType>(ArrayImgs.doubles(coefficients, 4, 4, 2));
// final ImagePlus imp = new ImagePlus( "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png" );
final ImagePlus imp1 = new ImagePlus("http://fly.mpi-cbg.de/~saalfeld/Pictures/norway.jpg");
final ArrayImg<FloatType, FloatArray> image1 = ArrayImgs.floats((float[]) imp1.getProcessor().convertToFloatProcessor().getPixels(), imp1.getWidth(), imp1.getHeight());
final ArrayImg<UnsignedByteType, ByteArray> image2 = ArrayImgs.unsignedBytes((byte[]) imp1.getProcessor().convertToByteProcessor().getPixels(), imp1.getWidth(), imp1.getHeight());
final ArrayImg<UnsignedShortType, ShortArray> image3 = ArrayImgs.unsignedShorts((short[]) imp1.getProcessor().convertToShortProcessor().getPixels(), imp1.getWidth(), imp1.getHeight());
final ArrayImg<ARGBType, IntArray> image4 = ArrayImgs.argbs((int[]) imp1.getProcessor().getPixels(), imp1.getWidth(), imp1.getHeight());
ImageJFunctions.show(ArrayImgs.doubles(coefficients, 4, 4, 2));
transform.run(image1);
transform.run(image2);
transform.run(image3);
transform.run(image4);
ImageJFunctions.show(image1);
ImageJFunctions.show(image2);
ImageJFunctions.show(image3);
ImageJFunctions.show(image4);
}
Aggregations