Search in sources :

Example 11 with FinalDimensions

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

the class AbstractFilterF method calculate.

/**
 * compute output by extending the input(s) and running the filter
 */
@Override
public RandomAccessibleInterval<O> calculate(final RandomAccessibleInterval<I> input, final RandomAccessibleInterval<K> kernel) {
    RandomAccessibleInterval<O> output = createOutput(input, kernel);
    final int numDimensions = input.numDimensions();
    // 1. Calculate desired extended size of the image
    final long[] paddedSize = new long[numDimensions];
    if (borderSize == null) {
        // if no border size was passed in, then extend based on kernel size
        for (int d = 0; d < numDimensions; ++d) {
            paddedSize[d] = (int) input.dimension(d) + (int) kernel.dimension(d) - 1;
        }
    } else {
        // if borderSize was passed in
        for (int d = 0; d < numDimensions; ++d) {
            paddedSize[d] = Math.max(kernel.dimension(d) + 2 * borderSize[d], input.dimension(d) + 2 * borderSize[d]);
        }
    }
    RandomAccessibleInterval<I> paddedInput = padOp.calculate(input, new FinalDimensions(paddedSize));
    RandomAccessibleInterval<K> paddedKernel = padKernelOp.calculate(kernel, new FinalDimensions(paddedSize));
    computeFilter(paddedInput, paddedKernel, output, paddedSize);
    return output;
}
Also used : FinalDimensions(net.imglib2.FinalDimensions)

Example 12 with FinalDimensions

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

the class PadInputFFT method calculate.

@Override
@SuppressWarnings("unchecked")
public O calculate(final I input, final Dimensions paddedDimensions) {
    Dimensions paddedFFTInputDimensions;
    // if an fftsize op has been set recompute padded size
    if (fftSizeOp != null) {
        long[][] sizes = fftSizeOp.calculate(paddedDimensions);
        paddedFFTInputDimensions = new FinalDimensions(sizes[0]);
    } else {
        paddedFFTInputDimensions = paddedDimensions;
    }
    if (obf == null) {
        obf = new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(input).createVariable());
    }
    Interval inputInterval = paddingIntervalCentered.calculate(input, paddedFFTInputDimensions);
    return (O) Views.interval(Views.extend(input, obf), inputInterval);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) FinalDimensions(net.imglib2.FinalDimensions) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Interval(net.imglib2.Interval)

Example 13 with FinalDimensions

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

the class PadShiftKernel method calculate.

@Override
@SuppressWarnings("unchecked")
public O calculate(final I kernel, final Dimensions paddedDimensions) {
    Dimensions paddedFFTInputDimensions;
    // if an fftsize op has been set recompute padded size
    if (fftSizeOp != null) {
        long[][] sizes = fftSizeOp.calculate(paddedDimensions);
        paddedFFTInputDimensions = new FinalDimensions(sizes[0]);
    } else {
        paddedFFTInputDimensions = paddedDimensions;
    }
    // compute where to place the final Interval for the kernel so that the
    // coordinate in the center
    // of the kernel is shifted to position (0,0).
    final Interval kernelConvolutionInterval = paddingIntervalCentered.calculate(kernel, paddedFFTInputDimensions);
    final Interval kernelConvolutionIntervalOrigin = paddingIntervalOrigin.calculate(kernel, kernelConvolutionInterval);
    return (O) Views.interval(Views.extendPeriodic(Views.interval(Views.extendValue(kernel, Util.getTypeFromInterval(kernel).createVariable()), kernelConvolutionInterval)), kernelConvolutionIntervalOrigin);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) FinalDimensions(net.imglib2.FinalDimensions) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Interval(net.imglib2.Interval)

Example 14 with FinalDimensions

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

the class NonCirculantNormalizationFactor method createNormalizationImageSemiNonCirculant.

protected void createNormalizationImageSemiNonCirculant() {
    // k is the window size (valid image region)
    final int length = k.numDimensions();
    final long[] n = new long[length];
    final long[] nFFT = new long[length];
    // also referred to as object space size
    for (int d = 0; d < length; d++) {
        n[d] = k.dimension(d) + l.dimension(d) - 1;
    }
    for (int d = 0; d < length; d++) {
        nFFT[d] = imgConvolutionInterval.dimension(d);
    }
    FinalDimensions fd = new FinalDimensions(nFFT);
    // create the normalization image
    normalization = create.calculate(fd);
    // size of the measurement window
    final Point size = new Point(length);
    final long[] sizel = new long[length];
    for (int d = 0; d < length; d++) {
        size.setPosition(k.dimension(d), d);
        sizel[d] = k.dimension(d);
    }
    // starting point of the measurement window when it is centered in fft space
    final Point start = new Point(length);
    final long[] startl = new long[length];
    final long[] endl = new long[length];
    for (int d = 0; d < length; d++) {
        start.setPosition((nFFT[d] - k.dimension(d)) / 2, d);
        startl[d] = (nFFT[d] - k.dimension(d)) / 2;
        endl[d] = startl[d] + sizel[d] - 1;
    }
    // size of the object space
    final Point maskSize = new Point(length);
    final long[] maskSizel = new long[length];
    for (int d = 0; d < length; d++) {
        maskSize.setPosition(Math.min(n[d], nFFT[d]), d);
        maskSizel[d] = Math.min(n[d], nFFT[d]);
    }
    // starting point of the object space within the fft space
    final Point maskStart = new Point(length);
    final long[] maskStartl = new long[length];
    for (int d = 0; d < length; d++) {
        maskStart.setPosition((Math.max(0, nFFT[d] - n[d]) / 2), d);
        maskStartl[d] = (Math.max(0, nFFT[d] - n[d]) / 2);
    }
    final RandomAccessibleInterval<O> temp = Views.interval(normalization, new FinalInterval(startl, endl));
    final Cursor<O> normCursor = Views.iterable(temp).cursor();
    // draw a cube the size of the measurement space
    while (normCursor.hasNext()) {
        normCursor.fwd();
        normCursor.get().setReal(1.0);
    }
    final Img<O> tempImg = create.calculate(fd);
    // 3. correlate psf with the output of step 2.
    correlater.compute(normalization, tempImg);
    normalization = tempImg;
    final Cursor<O> cursorN = normalization.cursor();
    while (cursorN.hasNext()) {
        cursorN.fwd();
        if (cursorN.get().getRealFloat() <= 1e-3f) {
            cursorN.get().setReal(1.0f);
        }
    }
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) FinalInterval(net.imglib2.FinalInterval) Point(net.imglib2.Point) Point(net.imglib2.Point)

Example 15 with FinalDimensions

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

the class FFTTest method testPadShiftKernel.

@Test
@SuppressWarnings("unchecked")
public void testPadShiftKernel() {
    long[] dims = new long[] { 1024, 1024 };
    Img<ComplexDoubleType> test = ops.create().img(new FinalDimensions(dims), new ComplexDoubleType());
    RandomAccessibleInterval<ComplexDoubleType> shift = (RandomAccessibleInterval<ComplexDoubleType>) ops.run(PadShiftKernel.class, test, new FinalDimensions(dims));
    RandomAccessibleInterval<ComplexDoubleType> shift2 = (RandomAccessibleInterval<ComplexDoubleType>) ops.run(PadShiftKernelFFTMethods.class, test, new FinalDimensions(dims));
    // assert there was no additional padding done by PadShiftKernel
    assertEquals(1024, shift.dimension(0));
    // assert that PadShiftKernelFFTMethods padded to the FFTMethods fast size
    assertEquals(1120, shift2.dimension(0));
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) PadShiftKernelFFTMethods(net.imagej.ops.filter.pad.PadShiftKernelFFTMethods) ComplexDoubleType(net.imglib2.type.numeric.complex.ComplexDoubleType) PadShiftKernel(net.imagej.ops.filter.pad.PadShiftKernel) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

FinalDimensions (net.imglib2.FinalDimensions)20 Dimensions (net.imglib2.Dimensions)9 AbstractOpTest (net.imagej.ops.AbstractOpTest)8 Test (org.junit.Test)8 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)5 Img (net.imglib2.img.Img)5 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)4 DoubleType (net.imglib2.type.numeric.real.DoubleType)4 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)3 BitType (net.imglib2.type.logic.BitType)3 ByteType (net.imglib2.type.numeric.integer.ByteType)3 CreateImgFromDimsAndType (net.imagej.ops.create.img.CreateImgFromDimsAndType)2 PadShiftKernelFFTMethods (net.imagej.ops.filter.pad.PadShiftKernelFFTMethods)2 FinalInterval (net.imglib2.FinalInterval)2 Interval (net.imglib2.Interval)2 Point (net.imglib2.Point)2 ArrayImgFactory (net.imglib2.img.array.ArrayImgFactory)2 IntType (net.imglib2.type.numeric.integer.IntType)2 FloatType (net.imglib2.type.numeric.real.FloatType)2 Before (org.junit.Before)2