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