Search in sources :

Example 1 with Op

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);
    }
}
Also used : Op(net.imagej.ops.Op) UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) Ops(net.imagej.ops.Ops) IncompatibleTypeException(net.imglib2.exception.IncompatibleTypeException) FloatType(net.imglib2.type.numeric.real.FloatType) ItemIO(org.scijava.ItemIO)

Example 2 with Op

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 });
}
Also used : AbstractOp(net.imagej.ops.AbstractOp) Op(net.imagej.ops.Op) Ops(net.imagej.ops.Ops)

Example 3 with Op

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;
}
Also used : Op(net.imagej.ops.Op) AbstractOp(net.imagej.ops.AbstractOp) UnaryFunctionOp(net.imagej.ops.special.function.UnaryFunctionOp) Type(java.lang.reflect.Type) UnaryHybridCF(net.imagej.ops.special.hybrid.UnaryHybridCF) UnaryFunctionOp(net.imagej.ops.special.function.UnaryFunctionOp)

Example 4 with Op

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);
}
Also used : Op(net.imagej.ops.Op)

Example 5 with Op

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);
}
Also used : Op(net.imagej.ops.Op)

Aggregations

Op (net.imagej.ops.Op)18 AbstractOpTest (net.imagej.ops.AbstractOpTest)11 Test (org.junit.Test)11 ByteType (net.imglib2.type.numeric.integer.ByteType)9 AbstractUnaryComputerOp (net.imagej.ops.special.computer.AbstractUnaryComputerOp)6 UnaryComputerOp (net.imagej.ops.special.computer.UnaryComputerOp)4 Ops (net.imagej.ops.Ops)3 MapOp (net.imagej.ops.map.MapOp)3 AbstractUnaryInplaceOp (net.imagej.ops.special.inplace.AbstractUnaryInplaceOp)3 BinaryInplaceOp (net.imagej.ops.special.inplace.BinaryInplaceOp)3 UnaryInplaceOp (net.imagej.ops.special.inplace.UnaryInplaceOp)3 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)3 AbstractOp (net.imagej.ops.AbstractOp)2 UnaryFunctionOp (net.imagej.ops.special.function.UnaryFunctionOp)2 FloatType (net.imglib2.type.numeric.real.FloatType)2 Type (java.lang.reflect.Type)1 NumericTypeBinaryMath (net.imagej.ops.math.NumericTypeBinaryMath)1 BinaryFunctionOp (net.imagej.ops.special.function.BinaryFunctionOp)1 UnaryHybridCF (net.imagej.ops.special.hybrid.UnaryHybridCF)1 IncompatibleTypeException (net.imglib2.exception.IncompatibleTypeException)1