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