Search in sources :

Example 1 with OutOfBoundsConstantValueFactory

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

the class DefaultDilate method initialize.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize() {
    minVal = Util.getTypeFromInterval(in()).createVariable();
    minVal.setReal(minVal.getMinValue());
    if (f == null) {
        f = new OutOfBoundsConstantValueFactory<>(minVal);
    }
    final UnaryComputerOp neighborComputer = minVal instanceof BitType ? new DilateBitType() : Computers.unary(ops(), Ops.Stats.Max.class, minVal.createVariable(), Iterable.class);
    imgCreator = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class, Img.class, in(), minVal.createVariable());
    if (out() == null)
        setOutput(createOutput(in()));
    mapper = ops().op(MapNeighborhood.class, out(), in1(), in2(), neighborComputer);
}
Also used : UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) AbstractUnaryComputerOp(net.imagej.ops.special.computer.AbstractUnaryComputerOp) Ops(net.imagej.ops.Ops) BitType(net.imglib2.type.logic.BitType) MapNeighborhood(net.imagej.ops.map.neighborhood.MapNeighborhood)

Example 2 with OutOfBoundsConstantValueFactory

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

the class DefaultErode method initialize.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize() {
    maxVal = Util.getTypeFromInterval(in()).createVariable();
    maxVal.setReal(maxVal.getMaxValue());
    if (f == null) {
        f = new OutOfBoundsConstantValueFactory<>(maxVal);
    }
    final UnaryComputerOp neighborComputer = maxVal instanceof BitType ? new ErodeBitType() : Computers.unary(ops(), Ops.Stats.Min.class, maxVal.createVariable(), Iterable.class);
    imgCreator = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class, Img.class, in(), maxVal.createVariable());
    if (out() == null)
        setOutput(createOutput(in()));
    mapper = ops().op(MapNeighborhood.class, out(), in1(), in2(), neighborComputer);
}
Also used : UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) AbstractUnaryComputerOp(net.imagej.ops.special.computer.AbstractUnaryComputerOp) Ops(net.imagej.ops.Ops) BitType(net.imglib2.type.logic.BitType) MapNeighborhood(net.imagej.ops.map.neighborhood.MapNeighborhood)

Example 3 with OutOfBoundsConstantValueFactory

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

the class DeconvolveTest method testDeconvolve.

@Test
public void testDeconvolve() {
    int[] size = new int[] { 225, 167 };
    int[] kernelSize = new int[] { 27, 39 };
    // create an input with a small sphere at the center
    Img<FloatType> in = new ArrayImgFactory<FloatType>().create(size, new FloatType());
    placeSphereInCenter(in);
    // create a kernel with a small sphere in the center
    Img<FloatType> kernel = new ArrayImgFactory<FloatType>().create(kernelSize, new FloatType());
    placeSphereInCenter(kernel);
    // convolve and calculate the sum of output
    @SuppressWarnings("unchecked") final Img<FloatType> convolved = (Img<FloatType>) ops.run(ConvolveFFTF.class, in, kernel);
    @SuppressWarnings("unchecked") final RandomAccessibleInterval<FloatType> deconvolved2 = (RandomAccessibleInterval<FloatType>) ops.run(RichardsonLucyF.class, convolved, kernel, null, new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(in).createVariable()), 10);
    assertEquals(size[0], deconvolved2.dimension(0));
    assertEquals(size[1], deconvolved2.dimension(1));
    final Cursor<FloatType> deconvolved2Cursor = Views.iterable(deconvolved2).cursor();
    float[] deconvolved2Values = { 1.0936068E-14f, 2.9685445E-14f, 4.280788E-15f, 3.032084E-18f, 1.1261E-39f, 0.0f, -8.7E-44f, -8.11881E-31f, -2.821192E-18f, 1.8687104E-20f, -2.927517E-23f, 1.2815774E-29f, -1.0611375E-19f, -5.2774515E-21f, -6.154334E-20f };
    for (int i = 0; i < deconvolved2Values.length; i++) {
        assertEquals(deconvolved2Values[i], deconvolved2Cursor.next().get(), 0.0f);
    }
}
Also used : Img(net.imglib2.img.Img) ConvolveFFTF(net.imagej.ops.filter.convolve.ConvolveFFTF) Point(net.imglib2.Point) FloatType(net.imglib2.type.numeric.real.FloatType) OutOfBoundsConstantValueFactory(net.imglib2.outofbounds.OutOfBoundsConstantValueFactory) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 4 with OutOfBoundsConstantValueFactory

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

the class DefaultDetectRidges method calculate.

@Override
public List<? extends WritablePolyline> calculate(RandomAccessibleInterval<T> input) {
    double sigma = (width / (2 * Math.sqrt(3)));
    // generate the metadata images
    RidgeDetectionMetadata ridgeDetectionMetadata = new RidgeDetectionMetadata(input, sigma, lowerThreshold, higherThreshold);
    // retrieve the metadata images
    Img<DoubleType> p_values = ridgeDetectionMetadata.getPValues();
    Img<DoubleType> n_values = ridgeDetectionMetadata.getNValues();
    Img<DoubleType> gradients = ridgeDetectionMetadata.getGradients();
    // create RandomAccesses for the metadata images
    OutOfBoundsConstantValueFactory<DoubleType, RandomAccessibleInterval<DoubleType>> oscvf = new OutOfBoundsConstantValueFactory<>(new DoubleType(0));
    RandomAccess<DoubleType> pRA = oscvf.create(p_values);
    RandomAccess<DoubleType> nRA = oscvf.create(n_values);
    RandomAccess<DoubleType> gradientRA = oscvf.create(gradients);
    // create the output polyline list.
    List<DefaultWritablePolyline> lines = new ArrayList<>();
    // start at the point of greatest maximum absolute value
    gradientRA.setPosition(RidgeDetectionUtils.getMaxCoords(gradients, true));
    // loop through the maximum values of the image
    while (Math.abs(gradientRA.get().get()) > higherThreshold) {
        // create the List of points that will be used to make the polyline
        List<RealPoint> points = new ArrayList<>();
        // get all of the necessary metadata from the image.
        long[] eigenvectorPos = { gradientRA.getLongPosition(0), gradientRA.getLongPosition(1), 0 };
        // obtain the n-values
        nRA.setPosition(eigenvectorPos);
        double eigenx = nRA.get().getRealDouble();
        nRA.fwd(2);
        double eigeny = nRA.get().getRealDouble();
        // obtain the p-values
        pRA.setPosition(eigenvectorPos);
        double px = pRA.get().getRealDouble();
        pRA.fwd(2);
        double py = pRA.get().getRealDouble();
        // start the list by adding the current point, which is the most line-like
        // point on the polyline
        points.add(RidgeDetectionUtils.get2DRealPoint(gradientRA.getDoublePosition(0) + px, gradientRA.getDoublePosition(1) + py));
        // go in the direction to the left of the perpendicular value
        getNextPoint(gradientRA, pRA, nRA, points, RidgeDetectionUtils.getOctant(eigenx, eigeny), eigenx, eigeny, px, py);
        // flip the array list around so that we get one cohesive line
        gradientRA.setPosition(new long[] { eigenvectorPos[0], eigenvectorPos[1] });
        Collections.reverse(points);
        // go in the opposite direction as before.
        eigenx = -eigenx;
        eigeny = -eigeny;
        getNextPoint(gradientRA, pRA, nRA, points, RidgeDetectionUtils.getOctant(eigenx, eigeny), eigenx, eigeny, px, py);
        // set the value to 0 so that it is not reused.
        gradientRA.get().setReal(0);
        // list has fewer vertices than the parameter, then we do not report it.
        if (points.size() > ridgeLengthMin) {
            DefaultWritablePolyline pline = new DefaultWritablePolyline(points);
            lines.add(pline);
        }
        // find the next max absolute value
        gradientRA.setPosition(RidgeDetectionUtils.getMaxCoords(gradients, true));
    }
    return lines;
}
Also used : DefaultWritablePolyline(net.imglib2.roi.geom.real.DefaultWritablePolyline) ArrayList(java.util.ArrayList) OutOfBoundsConstantValueFactory(net.imglib2.outofbounds.OutOfBoundsConstantValueFactory) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) DoubleType(net.imglib2.type.numeric.real.DoubleType) RealPoint(net.imglib2.RealPoint)

Example 5 with OutOfBoundsConstantValueFactory

use of net.imglib2.outofbounds.OutOfBoundsConstantValueFactory 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);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) FinalDimensions(net.imglib2.FinalDimensions) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Interval(net.imglib2.Interval)

Aggregations

RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)3 Ops (net.imagej.ops.Ops)2 MapNeighborhood (net.imagej.ops.map.neighborhood.MapNeighborhood)2 AbstractUnaryComputerOp (net.imagej.ops.special.computer.AbstractUnaryComputerOp)2 UnaryComputerOp (net.imagej.ops.special.computer.UnaryComputerOp)2 OutOfBoundsConstantValueFactory (net.imglib2.outofbounds.OutOfBoundsConstantValueFactory)2 BitType (net.imglib2.type.logic.BitType)2 ArrayList (java.util.ArrayList)1 AbstractOpTest (net.imagej.ops.AbstractOpTest)1 ConvolveFFTF (net.imagej.ops.filter.convolve.ConvolveFFTF)1 Dimensions (net.imglib2.Dimensions)1 FinalDimensions (net.imglib2.FinalDimensions)1 Interval (net.imglib2.Interval)1 Point (net.imglib2.Point)1 RealPoint (net.imglib2.RealPoint)1 Img (net.imglib2.img.Img)1 DefaultWritablePolyline (net.imglib2.roi.geom.real.DefaultWritablePolyline)1 DoubleType (net.imglib2.type.numeric.real.DoubleType)1 FloatType (net.imglib2.type.numeric.real.FloatType)1 Test (org.junit.Test)1