Search in sources :

Example 1 with FinalDimensions

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);
    }
}
Also used : FinalDimensions(net.imglib2.FinalDimensions)

Example 2 with FinalDimensions

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());
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) BitType(net.imglib2.type.logic.BitType)

Example 3 with FinalDimensions

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;
    }
}
Also used : Dimensions(net.imglib2.Dimensions) FinalDimensions(net.imglib2.FinalDimensions) FinalDimensions(net.imglib2.FinalDimensions) DoubleType(net.imglib2.type.numeric.real.DoubleType) ExecutorService(java.util.concurrent.ExecutorService) IncompatibleTypeException(net.imglib2.exception.IncompatibleTypeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with FinalDimensions

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);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions)

Example 5 with FinalDimensions

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;
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) FinalDimensions(net.imglib2.FinalDimensions)

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