Search in sources :

Example 1 with ArrayImg

use of net.imglib2.img.array.ArrayImg in project vcell by virtualcell.

the class ImportSBMLCommand method run.

@Override
public void run() {
    // Read SBML document
    SBMLDocument document = null;
    try {
        document = SBMLReader.read(file);
    } catch (XMLStreamException | IOException e) {
        e.printStackTrace();
    }
    // Get SBML geometry
    SpatialModelPlugin modelPlugin = (SpatialModelPlugin) document.getModel().getPlugin("spatial");
    Geometry geometry = modelPlugin.getGeometry();
    SampledField sampledField = geometry.getListOfSampledFields().get(0);
    // Parse pixel values to int
    String[] imgStringArray = sampledField.getSamples().split(" ");
    int[] imgArray = new int[imgStringArray.length];
    for (int i = 0; i < imgStringArray.length; i++) {
        imgArray[i] = Integer.parseInt(imgStringArray[i]);
    }
    // Create the image and display
    int width = sampledField.getNumSamples1();
    int height = sampledField.getNumSamples2();
    ArrayImg<UnsignedIntType, IntArray> img = ArrayImgs.unsignedInts(imgArray, width, height);
    displayService.createDisplay(img);
}
Also used : SBMLDocument(org.sbml.jsbml.SBMLDocument) SpatialModelPlugin(org.sbml.jsbml.ext.spatial.SpatialModelPlugin) IOException(java.io.IOException) Geometry(org.sbml.jsbml.ext.spatial.Geometry) XMLStreamException(javax.xml.stream.XMLStreamException) IntArray(net.imglib2.img.basictypeaccess.array.IntArray) SampledField(org.sbml.jsbml.ext.spatial.SampledField) UnsignedIntType(net.imglib2.type.numeric.integer.UnsignedIntType)

Example 2 with ArrayImg

use of net.imglib2.img.array.ArrayImg in project imagej-ops by imagej.

the class CreateImgTest method testImageFactory.

@Test
public void testImageFactory() {
    final Dimensions dim = new FinalDimensions(10, 10, 10);
    @SuppressWarnings("unchecked") final Img<DoubleType> arrayImg = (Img<DoubleType>) ops.run(CreateImgFromDimsAndType.class, dim, new DoubleType(), new ArrayImgFactory<DoubleType>());
    final Class<?> arrayFactoryClass = arrayImg.factory().getClass();
    assertEquals("Image Factory: ", ArrayImgFactory.class, arrayFactoryClass);
    @SuppressWarnings("unchecked") final Img<DoubleType> cellImg = (Img<DoubleType>) ops.run(CreateImgFromDimsAndType.class, dim, new DoubleType(), new CellImgFactory<DoubleType>());
    final Class<?> cellFactoryClass = cellImg.factory().getClass();
    assertEquals("Image Factory: ", CellImgFactory.class, cellFactoryClass);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) CreateImgFromImg(net.imagej.ops.create.img.CreateImgFromImg) Img(net.imglib2.img.Img) CellImgFactory(net.imglib2.img.cell.CellImgFactory) DoubleType(net.imglib2.type.numeric.real.DoubleType) CreateImgFromDimsAndType(net.imagej.ops.create.img.CreateImgFromDimsAndType) FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 3 with ArrayImg

use of net.imglib2.img.array.ArrayImg in project imagej-ops by imagej.

the class AbstractOpTest method generateUnsignedVariableBitLengthTypeArrayTestImg.

public ArrayImg<UnsignedVariableBitLengthType, LongArray> generateUnsignedVariableBitLengthTypeArrayTestImg(final boolean fill, final int nbits, final long... dims) {
    final long[] array = new long[(int) Intervals.numElements(new FinalInterval(dims))];
    if (fill) {
        seed = 17;
        for (int i = 0; i < array.length; i++) {
            array[i] = (long) (((pseudoRandom() / Integer.MAX_VALUE)) % (Math.pow(2, nbits)));
        }
    }
    final LongArray l = new LongArray(array);
    return ArrayImgs.unsignedVariableBitLengths(l, nbits, dims);
}
Also used : LongArray(net.imglib2.img.basictypeaccess.array.LongArray) FinalInterval(net.imglib2.FinalInterval)

Example 4 with ArrayImg

use of net.imglib2.img.array.ArrayImg in project imagej-ops by imagej.

the class AbstractOpTest method generateUnsigned128BitArrayTestImg.

public ArrayImg<Unsigned128BitType, LongArray> generateUnsigned128BitArrayTestImg(final boolean fill, final long... dims) {
    ArrayImg<Unsigned128BitType, LongArray> bits = ArrayImgs.unsigned128Bits(dims);
    if (fill) {
        MersenneTwisterFast betterRNG = new MersenneTwisterFast(0xf1eece);
        for (Unsigned128BitType b : bits) {
            BigInteger big = BigInteger.valueOf(betterRNG.nextLong());
            b.set(big);
        }
    }
    return bits;
}
Also used : LongArray(net.imglib2.img.basictypeaccess.array.LongArray) MersenneTwisterFast(org.scijava.util.MersenneTwisterFast) BigInteger(java.math.BigInteger) Unsigned128BitType(net.imglib2.type.numeric.integer.Unsigned128BitType)

Example 5 with ArrayImg

use of net.imglib2.img.array.ArrayImg 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

IntArray (net.imglib2.img.basictypeaccess.array.IntArray)2 LongArray (net.imglib2.img.basictypeaccess.array.LongArray)2 DoubleType (net.imglib2.type.numeric.real.DoubleType)2 ImageJ (ij.ImageJ)1 ImagePlus (ij.ImagePlus)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 AbstractOpTest (net.imagej.ops.AbstractOpTest)1 CreateImgFromDimsAndType (net.imagej.ops.create.img.CreateImgFromDimsAndType)1 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)1 Dimensions (net.imglib2.Dimensions)1 FinalDimensions (net.imglib2.FinalDimensions)1 FinalInterval (net.imglib2.FinalInterval)1 Img (net.imglib2.img.Img)1 ArrayImgFactory (net.imglib2.img.array.ArrayImgFactory)1 ByteArray (net.imglib2.img.basictypeaccess.array.ByteArray)1 FloatArray (net.imglib2.img.basictypeaccess.array.FloatArray)1 ShortArray (net.imglib2.img.basictypeaccess.array.ShortArray)1 CellImgFactory (net.imglib2.img.cell.CellImgFactory)1