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]);
}
}
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);
}
}
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);
}
}
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());
}
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());
}
Aggregations