Search in sources :

Example 31 with Dimensions

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

the class FrangiVesselness method run.

@Override
public void run() {
    // parse the spacing, and scales strings.
    spacing = checkDimensions(spacingString, input.numDimensions(), "Spacings");
    scales = Arrays.stream(scaleString.split(regex)).mapToInt(Integer::parseInt).toArray();
    Dimensions resultDims = Views.addDimension(input, 0, scales.length - 1);
    // create output image, potentially-filtered input
    result = opService.create().img(resultDims, new FloatType());
    for (int s = 0; s < scales.length; s++) {
        // Determine whether or not the user would like to apply the gaussian
        // beforehand and do it.
        RandomAccessibleInterval<T> vesselnessInput = doGauss ? opService.filter().gauss(input, scales[s]) : input;
        IntervalView<FloatType> scaleResult = Views.hyperSlice(result, result.numDimensions() - 1, s);
        opService.filter().frangiVesselness(scaleResult, vesselnessInput, spacing, scales[s]);
    }
}
Also used : Dimensions(net.imglib2.Dimensions) FloatType(net.imglib2.type.numeric.real.FloatType)

Example 32 with Dimensions

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

the class FFTTest method testFFT3DOp.

/**
 * test that a forward transform followed by an inverse transform gives us
 * back the original image
 */
@Test
public void testFFT3DOp() {
    final int min = expensiveTestsEnabled ? 115 : 9;
    final int max = expensiveTestsEnabled ? 120 : 11;
    for (int i = min; i < max; i++) {
        final long[] dimensions = new long[] { i, i, i };
        // create an input with a small sphere at the center
        final Img<FloatType> in = generateFloatArrayTestImg(false, dimensions);
        placeSphereInCenter(in);
        final Img<FloatType> inverse = generateFloatArrayTestImg(false, dimensions);
        @SuppressWarnings("unchecked") final Img<ComplexFloatType> out = (Img<ComplexFloatType>) ops.run(FFTMethodsOpF.class, in);
        ops.run(IFFTMethodsOpC.class, inverse, out);
        assertImagesEqual(in, inverse, .00005f);
    }
}
Also used : ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType) Img(net.imglib2.img.Img) Point(net.imglib2.Point) FFTMethodsOpF(net.imagej.ops.filter.fft.FFTMethodsOpF) FloatType(net.imglib2.type.numeric.real.FloatType) ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 33 with Dimensions

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

the class FFTTest method testFastFFT3DOp.

/**
 * test the fast FFT
 */
@Test
public void testFastFFT3DOp() {
    final int min = expensiveTestsEnabled ? 120 : 9;
    final int max = expensiveTestsEnabled ? 130 : 11;
    final int size = expensiveTestsEnabled ? 129 : 10;
    for (int i = min; i < max; i++) {
        // define the original dimensions
        final long[] originalDimensions = new long[] { i, size, size };
        // arrays for the fast dimensions
        final long[] fastDimensions = new long[3];
        final long[] fftDimensions = new long[3];
        // compute the dimensions that will result in the fastest FFT time
        ops.run(ComputeFFTSize.class, originalDimensions, fastDimensions, fftDimensions, true, true);
        // create an input with a small sphere at the center
        final Img<FloatType> inOriginal = generateFloatArrayTestImg(false, originalDimensions);
        placeSphereInCenter(inOriginal);
        // create a similar input using the fast size
        final Img<FloatType> inFast = generateFloatArrayTestImg(false, fastDimensions);
        placeSphereInCenter(inFast);
        // call FFT passing false for "fast" (in order to pass the optional
        // parameter we have to pass null for the
        // output parameter).
        @SuppressWarnings("unchecked") final RandomAccessibleInterval<ComplexFloatType> fft1 = (RandomAccessibleInterval<ComplexFloatType>) ops.run(FFTMethodsOpF.class, inOriginal, null, false);
        // call FFT passing true for "fast" The FFT op will pad the input to the
        // fast
        // size.
        @SuppressWarnings("unchecked") final RandomAccessibleInterval<ComplexFloatType> fft2 = (RandomAccessibleInterval<ComplexFloatType>) ops.run(FFTMethodsOpF.class, inOriginal, null, true);
        // call fft using the img that was created with the fast size
        @SuppressWarnings("unchecked") final RandomAccessibleInterval<ComplexFloatType> fft3 = (RandomAccessibleInterval<ComplexFloatType>) ops.run(FFTMethodsOpF.class, inFast);
        // create an image to be used for the inverse, using the original
        // size
        final Img<FloatType> inverseOriginalSmall = generateFloatArrayTestImg(false, originalDimensions);
        // create an inverse image to be used for the inverse, using the
        // original
        // size
        final Img<FloatType> inverseOriginalFast = generateFloatArrayTestImg(false, originalDimensions);
        // create an inverse image to be used for the inverse, using the
        // fast size
        final Img<FloatType> inverseFast = generateFloatArrayTestImg(false, fastDimensions);
        // invert the "small" FFT
        ops.run(IFFTMethodsOpC.class, inverseOriginalSmall, fft1);
        // invert the "fast" FFT. The inverse will should be the original
        // size.
        ops.run(IFFTMethodsOpC.class, inverseOriginalFast, fft2);
        // invert the "fast" FFT that was acheived by explicitly using an
        // image
        // that had "fast" dimensions. The inverse will be the fast size
        // this
        // time.
        ops.run(IFFTMethodsOpC.class, inverseFast, fft3);
        // assert that the inverse images are equal to the original
        assertImagesEqual(inverseOriginalSmall, inOriginal, .0001f);
        assertImagesEqual(inverseOriginalFast, inOriginal, .00001f);
        assertImagesEqual(inverseFast, inFast, 0.00001f);
    }
}
Also used : ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Point(net.imglib2.Point) FFTMethodsOpF(net.imagej.ops.filter.fft.FFTMethodsOpF) FloatType(net.imglib2.type.numeric.real.FloatType) ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 34 with Dimensions

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

the class CreateImgTest method testCreateFromRaiDifferentType.

@Test
public void testCreateFromRaiDifferentType() {
    final IntervalView<ByteType> input = Views.interval(PlanarImgs.bytes(10, 10, 10), new FinalInterval(new long[] { 10, 10, 1 }));
    final Img<?> res = (Img<?>) ops.run(CreateImgFromDimsAndType.class, input, new ShortType());
    assertEquals("Image Type: ", ShortType.class, res.firstElement().getClass());
    assertArrayEquals("Image Dimensions: ", Intervals.dimensionsAsLongArray(input), Intervals.dimensionsAsLongArray(res));
    assertEquals("Image Factory: ", ArrayImgFactory.class, res.factory().getClass());
}
Also used : CreateImgFromImg(net.imagej.ops.create.img.CreateImgFromImg) Img(net.imglib2.img.Img) CreateImgFromDimsAndType(net.imagej.ops.create.img.CreateImgFromDimsAndType) ShortType(net.imglib2.type.numeric.integer.ShortType) FinalInterval(net.imglib2.FinalInterval) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 35 with Dimensions

use of net.imglib2.Dimensions 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)

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