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);
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations