Search in sources :

Example 1 with Ops

use of net.imagej.ops.Ops in project imagej-ops by imagej.

the class GlobalThresholder method run.

@Override
public void run() {
    Op threshold = ops().op("threshold", out, in, method);
    // TODO actually map axes to int array
    ops().run(Ops.Slice.class, out, in, threshold, new int[] { 0, 1 });
}
Also used : AbstractOp(net.imagej.ops.AbstractOp) Op(net.imagej.ops.Op) Ops(net.imagej.ops.Ops)

Example 2 with Ops

use of net.imagej.ops.Ops 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 3 with Ops

use of net.imagej.ops.Ops 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 4 with Ops

use of net.imagej.ops.Ops in project imagej-ops by imagej.

the class LocalPhansalkarThreshold method unaryComputer.

@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass, final BitType outClass) {
    final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

        private UnaryComputerOp<Iterable<T>, DoubleType> mean;

        private UnaryComputerOp<Iterable<T>, DoubleType> stdDeviation;

        @Override
        public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {
            if (mean == null) {
                mean = Computers.unary(ops(), Ops.Stats.Mean.class, new DoubleType(), neighborhood);
            }
            if (stdDeviation == null) {
                stdDeviation = Computers.unary(ops(), Ops.Stats.StdDev.class, new DoubleType(), neighborhood);
            }
            final DoubleType meanValue = new DoubleType();
            mean.compute(neighborhood, meanValue);
            final DoubleType stdDevValue = new DoubleType();
            stdDeviation.compute(neighborhood, stdDevValue);
            double threshold = meanValue.get() * (1.0d + p * Math.exp(-q * meanValue.get()) + k * ((stdDevValue.get() / r) - 1.0));
            output.set(center.getRealDouble() >= threshold);
        }
    };
    op.setEnvironment(ops());
    return op;
}
Also used : UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) Ops(net.imagej.ops.Ops) BitType(net.imglib2.type.logic.BitType) DoubleType(net.imglib2.type.numeric.real.DoubleType) LocalThresholdMethod(net.imagej.ops.threshold.LocalThresholdMethod)

Example 5 with Ops

use of net.imagej.ops.Ops in project imagej-ops by imagej.

the class PartialDerivativeRAI method initialize.

@SuppressWarnings("unchecked")
@Override
public void initialize() {
    RandomAccessibleInterval<T> kernel = ops().create().kernelSobel(Util.getTypeFromInterval(in()));
    RandomAccessibleInterval<T> kernelA = Views.hyperSlice(Views.hyperSlice(kernel, 3, 0), 2, 0);
    RandomAccessibleInterval<T> kernelB = Views.hyperSlice(Views.hyperSlice(kernel, 3, 0), 2, 1);
    // add dimensions to kernel to rotate properly
    if (in().numDimensions() > 2) {
        RandomAccessible<T> expandedKernelA = Views.addDimension(kernelA);
        RandomAccessible<T> expandedKernelB = Views.addDimension(kernelB);
        for (int i = 0; i < in().numDimensions() - 3; i++) {
            expandedKernelA = Views.addDimension(expandedKernelA);
            expandedKernelB = Views.addDimension(expandedKernelB);
        }
        long[] dims = new long[in().numDimensions()];
        for (int j = 0; j < in().numDimensions(); j++) {
            dims[j] = 1;
        }
        dims[0] = 3;
        Interval kernelInterval = new FinalInterval(dims);
        kernelA = Views.interval(expandedKernelA, kernelInterval);
        kernelB = Views.interval(expandedKernelB, kernelInterval);
    }
    long[] dims = new long[in().numDimensions()];
    if (dimension == 0) {
        // FIXME hack
        kernelBConvolveOp = RAIs.computer(ops(), Ops.Filter.Convolve.class, in(), new Object[] { kernelB });
    } else {
        // rotate kernel B to dimension
        for (int j = 0; j < in().numDimensions(); j++) {
            if (j == dimension) {
                dims[j] = 3;
            } else {
                dims[j] = 1;
            }
        }
        Img<DoubleType> kernelInterval = ops().create().img(dims);
        RandomAccessibleInterval<T> rotatedKernelB = kernelB;
        for (int i = 0; i < dimension; i++) {
            rotatedKernelB = Views.rotate(rotatedKernelB, i, i + 1);
        }
        rotatedKernelB = Views.interval(rotatedKernelB, kernelInterval);
        kernelBConvolveOp = RAIs.computer(ops(), Ops.Filter.Convolve.class, in(), new Object[] { rotatedKernelB });
    }
    dims = null;
    // rotate kernel A to all other dimensions
    kernelAConvolveOps = new UnaryComputerOp[in().numDimensions()];
    if (dimension != 0) {
        kernelAConvolveOps[0] = RAIs.computer(ops(), Ops.Filter.Convolve.class, in(), new Object[] { kernelA });
    }
    RandomAccessibleInterval<T> rotatedKernelA = kernelA;
    for (int i = 1; i < in().numDimensions(); i++) {
        if (i != dimension) {
            dims = new long[in().numDimensions()];
            for (int j = 0; j < in().numDimensions(); j++) {
                if (i == j) {
                    dims[j] = 3;
                } else {
                    dims[j] = 1;
                }
            }
            Img<DoubleType> kernelInterval = ops().create().img(dims);
            for (int j = 0; j < i; j++) {
                rotatedKernelA = Views.rotate(rotatedKernelA, j, j + 1);
            }
            kernelAConvolveOps[i] = RAIs.computer(ops(), Ops.Filter.Convolve.class, in(), new Object[] { Views.interval(rotatedKernelA, kernelInterval) });
            rotatedKernelA = kernelA;
        }
    }
    addOp = RAIs.binaryComputer(ops(), Ops.Math.Add.class, in(), in());
    createRAI = RAIs.function(ops(), Ops.Create.Img.class, in());
}
Also used : Img(net.imglib2.img.Img) Ops(net.imagej.ops.Ops) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalInterval(net.imglib2.FinalInterval) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Interval(net.imglib2.Interval) FinalInterval(net.imglib2.FinalInterval)

Aggregations

Ops (net.imagej.ops.Ops)17 UnaryComputerOp (net.imagej.ops.special.computer.UnaryComputerOp)8 BitType (net.imglib2.type.logic.BitType)8 DoubleType (net.imglib2.type.numeric.real.DoubleType)8 LocalThresholdMethod (net.imagej.ops.threshold.LocalThresholdMethod)5 Img (net.imglib2.img.Img)4 Test (org.junit.Test)4 AbstractOpTest (net.imagej.ops.AbstractOpTest)3 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)3 ArrayList (java.util.ArrayList)2 MapNeighborhood (net.imagej.ops.map.neighborhood.MapNeighborhood)2 AbstractUnaryComputerOp (net.imagej.ops.special.computer.AbstractUnaryComputerOp)2 Interval (net.imglib2.Interval)2 ByteType (net.imglib2.type.numeric.integer.ByteType)2 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 PriorityQueue (java.util.PriorityQueue)1 Set (java.util.Set)1