Search in sources :

Example 26 with Dimensions

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

the class Outline method createOutput.

@Override
public RandomAccessibleInterval<BitType> createOutput(final RandomAccessibleInterval<B> input, final Boolean input2) {
    final long[] dims = new long[input.numDimensions()];
    input.dimensions(dims);
    final FinalDimensions dimensions = new FinalDimensions(dims);
    return ops().create().img(dimensions, new BitType());
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) BitType(net.imglib2.type.logic.BitType)

Example 27 with Dimensions

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

the class IntegralMean method compute.

@Override
public void compute(final RectangleNeighborhood<Composite<I>> input, final DoubleType output) {
    // computation according to
    // https://en.wikipedia.org/wiki/Summed_area_table
    final IntegralCursor<Composite<I>> cursor = new IntegralCursor<>(input);
    final int dimensions = input.numDimensions();
    // Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
    final DoubleType sum = new DoubleType();
    sum.setZero();
    // Convert from input to return type
    final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
    final DoubleType valueAsDoubleType = new DoubleType();
    while (cursor.hasNext()) {
        final I value = cursor.next().get(0).copy();
        conv.convert(value, valueAsDoubleType);
        // Obtain the cursor position encoded as corner vector
        final int cornerInteger = cursor.getCornerRepresentation();
        // Determine if the value has to be added (factor==1) or subtracted
        // (factor==-1)
        final DoubleType factor = new DoubleType(Math.pow(-1.0d, dimensions - IntegralMean.norm(cornerInteger)));
        valueAsDoubleType.mul(factor);
        sum.add(valueAsDoubleType);
    }
    final int area = (int) Intervals.numElements(Intervals.expand(input, -1l));
    // Compute mean by dividing the sum divided by the number of elements
    // NB: Reuse DoubleType
    valueAsDoubleType.set(area);
    sum.div(valueAsDoubleType);
    output.set(sum);
}
Also used : Composite(net.imglib2.view.composite.Composite) DoubleType(net.imglib2.type.numeric.real.DoubleType) IntegralCursor(net.imagej.ops.image.integral.IntegralCursor) RealDoubleConverter(net.imglib2.converter.RealDoubleConverter)

Example 28 with Dimensions

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

the class IntegralSum method compute.

@Override
public void compute(final RectangleNeighborhood<I> input, final DoubleType output) {
    // computation according to
    // https://en.wikipedia.org/wiki/Summed_area_table
    final IntegralCursor<I> cursor = new IntegralCursor<>(input);
    final int dimensions = input.numDimensions();
    // Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
    final DoubleType sum = new DoubleType();
    sum.setZero();
    // Convert from input to return type
    final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
    final DoubleType valueAsDoubleType = new DoubleType();
    while (cursor.hasNext()) {
        final I value = cursor.next().copy();
        conv.convert(value, valueAsDoubleType);
        // Obtain the cursor position encoded as corner vector
        final int cornerInteger = cursor.getCornerRepresentation();
        // Determine if the value has to be added (factor==1) or subtracted
        // (factor==-1)
        final DoubleType factor = new DoubleType(Math.pow(-1.0d, dimensions - IntegralMean.norm(cornerInteger)));
        valueAsDoubleType.mul(factor);
        sum.add(valueAsDoubleType);
    }
    output.set(sum);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) IntegralCursor(net.imagej.ops.image.integral.IntegralCursor) RealDoubleConverter(net.imglib2.converter.RealDoubleConverter)

Example 29 with Dimensions

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

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

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