Search in sources :

Example 36 with Dimensions

use of net.imglib2.Dimensions 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());
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) Img(net.imglib2.img.Img) Dimensions(net.imglib2.Dimensions) FinalDimensions(net.imglib2.FinalDimensions) IntType(net.imglib2.type.numeric.integer.IntType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 37 with Dimensions

use of net.imglib2.Dimensions in project imagej-ops by imagej.

the class CreateImgTest method testImageMinimum.

@Test
public void testImageMinimum() {
    final Random randomGenerator = new Random();
    for (int i = 0; i < TEST_SIZE; i++) {
        // between 2 and 5 dimensions
        final long[] max = new long[randomGenerator.nextInt(4) + 2];
        final long[] min = new long[max.length];
        // between 2 and 10 pixels per dimensions
        for (int j = 0; j < max.length; j++) {
            max[j] = randomGenerator.nextInt(9) + 2;
            min[j] = Math.max(0, max[j] - randomGenerator.nextInt(4));
        }
        // create img
        final Img<?> img = (Img<?>) ops.run(CreateImgFromInterval.class, new FinalInterval(min, max));
        assertArrayEquals("Image Minimum:", min, Intervals.minAsLongArray(img));
        assertArrayEquals("Image Maximum:", max, Intervals.maxAsLongArray(img));
    }
}
Also used : CreateImgFromInterval(net.imagej.ops.create.img.CreateImgFromInterval) CreateImgFromImg(net.imagej.ops.create.img.CreateImgFromImg) Img(net.imglib2.img.Img) Random(java.util.Random) FinalInterval(net.imglib2.FinalInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 38 with Dimensions

use of net.imglib2.Dimensions in project TrakEM2 by trakem2.

the class LinearIntensityMap method run.

@SuppressWarnings({ "rawtypes", "unchecked" })
public <S extends NumericType<S>> void run(final RandomAccessibleInterval<S> image) {
    assert image.numDimensions() == dimensions.numDimensions() : "Number of dimensions do not match.";
    final double[] s = new double[dimensions.numDimensions()];
    for (int d = 0; d < s.length; ++d) s[d] = image.dimension(d) / dimensions.dimension(d);
    final Scale scale = new Scale(s);
    // System.out.println( "translation-n " + translation.numDimensions() );
    final RandomAccessibleInterval<RealComposite<T>> stretchedCoefficients = Views.offsetInterval(Views.raster(RealViews.transform(RealViews.transform(coefficients, translation), scale)), image);
    /* decide on type which mapping to use */
    final S t = image.randomAccess().get();
    if (ARGBType.class.isInstance(t))
        mapARGB(Views.flatIterable((RandomAccessibleInterval<ARGBType>) image), Views.flatIterable(stretchedCoefficients));
    else if (RealComposite.class.isInstance(t))
        mapComposite(Views.flatIterable((RandomAccessibleInterval) image), Views.flatIterable(stretchedCoefficients));
    else if (RealType.class.isInstance(t)) {
        final RealType<?> r = (RealType) t;
        if (r.getMinValue() > -Double.MAX_VALUE || r.getMaxValue() < Double.MAX_VALUE)
            // TODO Bug in javac does not enable cast from RandomAccessibleInterval< S > to RandomAccessibleInterval< RealType >, remove when fixed
            mapCrop(Views.flatIterable((RandomAccessibleInterval<RealType>) (Object) image), Views.flatIterable(stretchedCoefficients));
        else
            // TODO Bug in javac does not enable cast from RandomAccessibleInterval< S > to RandomAccessibleInterval< RealType >, remove when fixed
            map(Views.flatIterable((RandomAccessibleInterval<RealType>) (Object) image), Views.flatIterable(stretchedCoefficients));
    }
}
Also used : RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Scale(net.imglib2.realtransform.Scale) ARGBType(net.imglib2.type.numeric.ARGBType) RealComposite(net.imglib2.view.composite.RealComposite) RealType(net.imglib2.type.numeric.RealType)

Aggregations

AbstractOpTest (net.imagej.ops.AbstractOpTest)14 Img (net.imglib2.img.Img)14 Test (org.junit.Test)14 DoubleType (net.imglib2.type.numeric.real.DoubleType)13 FinalDimensions (net.imglib2.FinalDimensions)12 Dimensions (net.imglib2.Dimensions)10 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)9 FinalInterval (net.imglib2.FinalInterval)8 FloatType (net.imglib2.type.numeric.real.FloatType)8 Ops (net.imagej.ops.Ops)6 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)5 BitType (net.imglib2.type.logic.BitType)5 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4 CreateImgFromDimsAndType (net.imagej.ops.create.img.CreateImgFromDimsAndType)4 File (java.io.File)3 Dataset (net.imagej.Dataset)3 IntegralCursor (net.imagej.ops.image.integral.IntegralCursor)3 ByteType (net.imglib2.type.numeric.integer.ByteType)3 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)3