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