Search in sources :

Example 1 with OutOfBoundsBorderFactory

use of net.imglib2.outofbounds.OutOfBoundsBorderFactory 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 2 with OutOfBoundsBorderFactory

use of net.imglib2.outofbounds.OutOfBoundsBorderFactory in project imagej-ops by imagej.

the class ExtendViewTest method defaultExtendTest.

@Test
public void defaultExtendTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    OutOfBounds<DoubleType> il2 = Views.extend(img, new OutOfBoundsBorderFactory<DoubleType, RandomAccessibleInterval<DoubleType>>()).randomAccess();
    OutOfBounds<DoubleType> opr = ops.transform().extendView(img, new OutOfBoundsBorderFactory<DoubleType, RandomAccessibleInterval<DoubleType>>()).randomAccess();
    il2.setPosition(new int[] { -1, -1 });
    opr.setPosition(new int[] { -1, -1 });
    assertEquals(il2.get().get(), opr.get().get(), 1e-10);
    il2.setPosition(new int[] { 11, 11 });
    opr.setPosition(new int[] { 11, 11 });
    assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) OutOfBoundsBorderFactory(net.imglib2.outofbounds.OutOfBoundsBorderFactory) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

DoubleType (net.imglib2.type.numeric.real.DoubleType)2 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 AbstractOpTest (net.imagej.ops.AbstractOpTest)1 Dimensions (net.imglib2.Dimensions)1 FinalDimensions (net.imglib2.FinalDimensions)1 IncompatibleTypeException (net.imglib2.exception.IncompatibleTypeException)1 OutOfBoundsBorderFactory (net.imglib2.outofbounds.OutOfBoundsBorderFactory)1 Test (org.junit.Test)1