use of net.imagej.ops.Op 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.Op 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.Op in project imagej-ops by imagej.
the class CachedOpEnvironment method op.
@Override
public Op op(final OpRef ref) {
final Op op = super.op(ref);
for (final Class<?> ignored : ignoredOps) {
for (final Type t : ref.getTypes()) {
// FIXME: Use generic assignability test, once it exists.
final Class<?> raw = GenericUtils.getClass(t);
if (ignored.isAssignableFrom(raw)) {
return op;
}
}
}
final Op cachedOp;
if (op instanceof UnaryHybridCF) {
cachedOp = wrapUnaryHybrid((UnaryHybridCF<?, ?>) op);
} else if (op instanceof UnaryFunctionOp) {
cachedOp = wrapUnaryFunction((UnaryFunctionOp<?, ?>) op);
} else
return op;
getContext().inject(cachedOp);
return cachedOp;
}
use of net.imagej.ops.Op in project imagej-ops by imagej.
the class InvertTest method assertDefaultInvert.
private <T extends RealType<T>> void assertDefaultInvert(final Img<T> in, final Img<T> out) {
final T type = in.firstElement();
final T min = type.copy();
min.setReal(type.getMinValue());
final T max = type.copy();
max.setReal(type.getMaxValue());
final Op op = ops.op(Ops.Image.Invert.class, out, in);
assertSame(InvertII.class, op.getClass());
op.run();
defaultCompare(in, out, min, max);
}
use of net.imagej.ops.Op in project imagej-ops by imagej.
the class InvertTest method assertIntegerInvertMinMaxProvided.
private <T extends IntegerType<T>> void assertIntegerInvertMinMaxProvided(final Img<T> in, final Img<T> out, final T min, final T max) {
// unsigned type test
final Op op = ops.op(Ops.Image.Invert.class, out, in, min, max);
assertSame(InvertIIInteger.class, op.getClass());
op.run();
integerCompare(in, out, min, max);
}
Aggregations