use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class VectorAccelerator method initialize.
public void initialize(RandomAccessibleInterval<T> yk_iterated) {
if (yk_prediction == null) {
long[] temp = new long[yk_iterated.numDimensions()];
yk_iterated.dimensions(temp);
FinalDimensions dims = new FinalDimensions(temp);
yk_prediction = create.calculate(dims);
xkm1_previous = create.calculate(dims);
yk_prediction = create.calculate(dims);
gk = create.calculate(dims);
hk_vector = create.calculate(dims);
}
}
use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class AbstractThin method createOutput.
@Override
public RandomAccessibleInterval<BitType> createOutput(final RandomAccessibleInterval<BitType> input) {
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.FinalDimensions in project imagej-ops by imagej.
the class DefaultTubeness method compute.
@Override
public void compute(final RandomAccessibleInterval<T> input, final IterableInterval<DoubleType> tubeness) {
cancelReason = null;
final int numDimensions = input.numDimensions();
// Sigmas in pixel units.
final double[] sigmas = new double[numDimensions];
for (int d = 0; d < sigmas.length; d++) {
final double cal = d < calibration.length ? calibration[d] : 1;
sigmas[d] = sigma / cal;
}
/*
* Hessian.
*/
// Get a suitable image factory.
final long[] gradientDims = new long[numDimensions + 1];
final long[] hessianDims = new long[numDimensions + 1];
for (int d = 0; d < numDimensions; d++) {
hessianDims[d] = input.dimension(d);
gradientDims[d] = input.dimension(d);
}
hessianDims[numDimensions] = numDimensions * (numDimensions + 1) / 2;
gradientDims[numDimensions] = numDimensions;
final Dimensions hessianDimensions = FinalDimensions.wrap(hessianDims);
final FinalDimensions gradientDimensions = FinalDimensions.wrap(gradientDims);
final ImgFactory<DoubleType> factory = ops().create().imgFactory(hessianDimensions);
final Img<DoubleType> hessian = factory.create(hessianDimensions, new DoubleType());
final Img<DoubleType> gradient = factory.create(gradientDimensions, new DoubleType());
final Img<DoubleType> gaussian = factory.create(input, new DoubleType());
// Handle multithreading.
final int nThreads = Runtime.getRuntime().availableProcessors();
final ExecutorService es = threadService.getExecutorService();
try {
// Hessian calculation.
HessianMatrix.calculateMatrix(Views.extendBorder(input), gaussian, gradient, hessian, new OutOfBoundsBorderFactory<>(), nThreads, es, sigma);
statusService.showProgress(1, 3);
if (isCanceled())
return;
// Hessian eigenvalues.
final RandomAccessibleInterval<DoubleType> evs = TensorEigenValues.calculateEigenValuesSymmetric(hessian, TensorEigenValues.createAppropriateResultImg(hessian, factory, new DoubleType()), nThreads, es);
statusService.showProgress(2, 3);
if (isCanceled())
return;
final AbstractUnaryComputerOp<Iterable<DoubleType>, DoubleType> method;
switch(numDimensions) {
case 2:
method = new Tubeness2D(sigma);
break;
case 3:
method = new Tubeness3D(sigma);
break;
default:
System.err.println("Cannot compute tubeness for " + numDimensions + "D images.");
return;
}
ops().transform().project(tubeness, evs, method, numDimensions);
statusService.showProgress(3, 3);
return;
} catch (final IncompatibleTypeException | InterruptedException | ExecutionException e) {
e.printStackTrace();
return;
}
}
use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class AbstractFFTFilterF method computeFilter.
/**
* create FFT memory, create FFT filter and run it
*/
@Override
public void computeFilter(final RandomAccessibleInterval<I> input, final RandomAccessibleInterval<K> kernel, RandomAccessibleInterval<O> output, long[] paddedSize) {
RandomAccessibleInterval<C> fftInput = createOp.calculate(new FinalDimensions(paddedSize));
RandomAccessibleInterval<C> fftKernel = createOp.calculate(new FinalDimensions(paddedSize));
// TODO: in this case it is difficult to match the filter op in the
// 'initialize' as we don't know the size yet, thus we can't create
// memory
// for the FFTs
filter = createFilterComputer(input, kernel, fftInput, fftKernel, output, input);
filter.compute(input, kernel, output);
}
use of net.imglib2.FinalDimensions in project imagej-ops by imagej.
the class FFTMethodsOpF method calculate.
@Override
public RandomAccessibleInterval<C> calculate(final RandomAccessibleInterval<T> input) {
// calculate the padded size
long[] paddedSize = new long[in().numDimensions()];
for (int d = 0; d < in().numDimensions(); d++) {
paddedSize[d] = in().dimension(d);
if (borderSize != null) {
paddedSize[d] += borderSize[d];
}
}
Dimensions paddedDimensions = new FinalDimensions(paddedSize);
// create the complex output
RandomAccessibleInterval<C> output = createOp.calculate(paddedDimensions);
// pad the input
RandomAccessibleInterval<T> paddedInput = padOp.calculate(input, paddedDimensions);
// compute and return fft
fftMethodsOp.compute(paddedInput, output);
return output;
}
Aggregations