use of net.imagej.ops.threshold.LocalThresholdMethod 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;
}
use of net.imagej.ops.threshold.LocalThresholdMethod 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;
}
use of net.imagej.ops.threshold.LocalThresholdMethod 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;
}
use of net.imagej.ops.threshold.LocalThresholdMethod 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;
}
use of net.imagej.ops.threshold.LocalThresholdMethod 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;
}
Aggregations