Search in sources :

Example 11 with UnsignedByteType

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());
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) CreateImgFromImg(net.imagej.ops.create.img.CreateImgFromImg) Img(net.imglib2.img.Img) BitType(net.imglib2.type.logic.BitType) CreateImgFromDimsAndType(net.imagej.ops.create.img.CreateImgFromDimsAndType) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) ByteType(net.imglib2.type.numeric.integer.ByteType) IntType(net.imglib2.type.numeric.integer.IntType) FloatType(net.imglib2.type.numeric.real.FloatType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 12 with UnsignedByteType

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;
}
Also used : Random(java.util.Random) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType)

Example 13 with UnsignedByteType

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);
    }
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) Random(java.util.Random) PlanarImgFactory(net.imglib2.img.planar.PlanarImgFactory) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) FinalInterval(net.imglib2.FinalInterval) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) Before(org.junit.Before)

Example 14 with UnsignedByteType

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);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) IntervalView(net.imglib2.view.IntervalView) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) UnaryHybridCF(net.imagej.ops.special.hybrid.UnaryHybridCF) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 15 with UnsignedByteType

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);
}
Also used : UnsignedShortType(net.imglib2.type.numeric.integer.UnsignedShortType) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) ImagePlus(ij.ImagePlus) FloatType(net.imglib2.type.numeric.real.FloatType) ImageJ(ij.ImageJ) FloatArray(net.imglib2.img.basictypeaccess.array.FloatArray) IntArray(net.imglib2.img.basictypeaccess.array.IntArray) DoubleType(net.imglib2.type.numeric.real.DoubleType) ByteArray(net.imglib2.img.basictypeaccess.array.ByteArray) ARGBType(net.imglib2.type.numeric.ARGBType) ShortArray(net.imglib2.img.basictypeaccess.array.ShortArray)

Aggregations

UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)14 DoubleType (net.imglib2.type.numeric.real.DoubleType)5 Random (java.util.Random)4 AbstractOpTest (net.imagej.ops.AbstractOpTest)4 Test (org.junit.Test)4 FinalDimensions (net.imglib2.FinalDimensions)3 Img (net.imglib2.img.Img)3 BitType (net.imglib2.type.logic.BitType)3 File (java.io.File)2 IOException (java.io.IOException)2 Dataset (net.imagej.Dataset)2 ImgPlus (net.imagej.ImgPlus)2 FinalInterval (net.imglib2.FinalInterval)2 ArrayImgFactory (net.imglib2.img.array.ArrayImgFactory)2 FloatType (net.imglib2.type.numeric.real.FloatType)2 ImageJ (ij.ImageJ)1 ImagePlus (ij.ImagePlus)1 BufferedImage (java.awt.image.BufferedImage)1 BigDecimal (java.math.BigDecimal)1 URL (java.net.URL)1