Search in sources :

Example 1 with UnaryComputerOp

use of net.imagej.ops.special.computer.UnaryComputerOp in project imagej-ops by imagej.

the class Convolve method run.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void run() {
    // TODO: get the dimension indices from the image dependent on the
    // selected
    // axes -> OR: just map the kernel dimension labels to the image
    // dimension
    // labels
    final int[] axisIndices = new int[] { 0, 1 };
    // number of indicies must be conform with the dimensionality of axes
    if (axes.length != axisIndices.length) {
        throw new IllegalArgumentException("The number of selected dimension doesn't conforms with the kernel size.");
    }
    if (asFloat) {
        try {
            out = (ImgPlus) in.factory().imgFactory(new FloatType()).create(in, new FloatType());
        } catch (final IncompatibleTypeException e) {
            throw new IllegalArgumentException(e);
        }
    } else {
        out = (ImgPlus<O>) in.factory().create(in, in.firstElement().createVariable());
    }
    final Op op = ops.op(Ops.Filter.Convolve.class, out, in, kernel);
    if (in.numDimensions() > kernel.numDimensions()) {
        if (op instanceof UnaryComputerOp) {
            // if the selected convolve op is a function and the kernel dimensions
            // doesn't match the input image dimensions, than we can still convolve
            // each slice individually
            ops.run(Ops.Slice.class, out, in, op, axisIndices);
        } else {
            throw new IllegalArgumentException("The input image has more dimensions than the kernel!");
        }
    } else if (in.numDimensions() == kernel.numDimensions()) {
        // no 'slicing' necessary
        ops.run(op, out, in, kernel);
    }
}
Also used : Op(net.imagej.ops.Op) UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) Ops(net.imagej.ops.Ops) IncompatibleTypeException(net.imglib2.exception.IncompatibleTypeException) FloatType(net.imglib2.type.numeric.real.FloatType) ItemIO(org.scijava.ItemIO)

Example 2 with UnaryComputerOp

use of net.imagej.ops.special.computer.UnaryComputerOp 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 UnaryComputerOp

use of net.imagej.ops.special.computer.UnaryComputerOp 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 UnaryComputerOp

use of net.imagej.ops.special.computer.UnaryComputerOp 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 UnaryComputerOp

use of net.imagej.ops.special.computer.UnaryComputerOp in project imagej-ops by imagej.

the class LocalMeanThreshold 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> meanOp;

        @Override
        public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {
            if (meanOp == null) {
                meanOp = Computers.unary(ops(), Ops.Stats.Mean.class, DoubleType.class, neighborhood);
            }
            final DoubleType m = new DoubleType();
            meanOp.compute(neighborhood, m);
            output.set(center.getRealDouble() > m.getRealDouble() - c);
        }
    };
    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)

Aggregations

Ops (net.imagej.ops.Ops)9 UnaryComputerOp (net.imagej.ops.special.computer.UnaryComputerOp)9 BitType (net.imglib2.type.logic.BitType)7 DoubleType (net.imglib2.type.numeric.real.DoubleType)6 LocalThresholdMethod (net.imagej.ops.threshold.LocalThresholdMethod)5 MapNeighborhood (net.imagej.ops.map.neighborhood.MapNeighborhood)2 AbstractUnaryComputerOp (net.imagej.ops.special.computer.AbstractUnaryComputerOp)2 Op (net.imagej.ops.Op)1 AbstractCenterAwareComputerOp (net.imagej.ops.map.neighborhood.AbstractCenterAwareComputerOp)1 IncompatibleTypeException (net.imglib2.exception.IncompatibleTypeException)1 FloatType (net.imglib2.type.numeric.real.FloatType)1 ItemIO (org.scijava.ItemIO)1