Search in sources :

Example 11 with Ops

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

Example 12 with Ops

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

the class LocalMedianThreshold 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> median;

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

Example 13 with Ops

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

the class LocalNiblackThreshold 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 m = new DoubleType();
            mean.compute(neighborhood, m);
            final DoubleType stdDev = new DoubleType();
            stdDeviation.compute(neighborhood, stdDev);
            output.set(center.getRealDouble() > m.getRealDouble() + k * stdDev.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)

Example 14 with Ops

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

the class LocalSauvolaThreshold 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 + k * ((Math.sqrt(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 15 with Ops

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

the class DefaultSigmaFilter method unaryComputer.

@Override
protected CenterAwareComputerOp<T, V> unaryComputer(final T inType, final V outType) {
    final AbstractCenterAwareComputerOp<T, V> op = new AbstractCenterAwareComputerOp<T, V>() {

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

        @Override
        public void compute(final Iterable<T> neighborhood, final T center, final V output) {
            if (variance == null) {
                variance = Computers.unary(ops(), Ops.Stats.Variance.class, DoubleType.class, neighborhood);
            }
            DoubleType varianceResult = new DoubleType();
            variance.compute(neighborhood, varianceResult);
            double varianceValue = varianceResult.getRealDouble() * range;
            final double centerValue = center.getRealDouble();
            double sumAll = 0;
            double sumWithin = 0;
            long countAll = 0;
            long countWithin = 0;
            for (T neighbor : neighborhood) {
                final double pixelValue = neighbor.getRealDouble();
                final double diff = centerValue - pixelValue;
                sumAll += pixelValue;
                ++countAll;
                if (diff > varianceValue || diff < -varianceValue) {
                    continue;
                }
                // pixel within variance range
                sumWithin += pixelValue;
                ++countWithin;
            }
            if (countWithin < (int) (minPixelFraction * countAll)) {
                // simply mean
                output.setReal(sumAll / countAll);
            } else {
                // mean over pixels in variance range only
                output.setReal(sumWithin / countWithin);
            }
        }
    };
    op.setEnvironment(ops());
    return op;
}
Also used : AbstractCenterAwareComputerOp(net.imagej.ops.map.neighborhood.AbstractCenterAwareComputerOp) UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) Ops(net.imagej.ops.Ops) DoubleType(net.imglib2.type.numeric.real.DoubleType)

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