net.imagej.ops.Op Java Examples

The following examples show how to use net.imagej.ops.Op. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private <T extends IntegerType<T>> void
	assertIntegerInvert(final Img<T> in, final Img<T> out)
{

	final Op op = ops.op(Ops.Image.Invert.class, out, in);
	assertSame(InvertIIInteger.class, op.getClass());
	op.run();
	
	Cursor<T> inCursor = in.localizingCursor();
	Cursor<T> outCursor = out.localizingCursor();
	
	while(inCursor.hasNext()) {
		inCursor.fwd();
		outCursor.fwd();
	}
	
	integerCompare(in, out, null, null);
}
 
Example #2
Source File: IIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> UnaryFunctionOp<IterableInterval<T>, IterableInterval<T>>
	function(final OpEnvironment ops, final Class<? extends Op> opType,
		final IterableInterval<T> in, final Object... otherArgs)
{
	return (UnaryFunctionOp) Functions.unary(ops, opType,
		IterableInterval.class, in == null ? IterableInterval.class : in,
		otherArgs);
}
 
Example #3
Source File: Colocalize.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void calculateRow(Class<? extends Op> opType, Column<String> algorithmColumn, DoubleColumn pValueColumn,
		DoubleColumn colocValueColumn, Column<double[]> colocArrayColumn, String algorithmName, Dimensions psfSize) {
	BinaryFunctionOp<Iterable<T>, Iterable<T>, Double> colocOp = Functions.binary(ops, opType, Double.class, image1, image2);
	PValueResult result = new PValueResult();
	ops.run(Ops.Coloc.PValue.class, result, image1, image2, colocOp, 100, psfSize);
	algorithmColumn.add(algorithmName);
	pValueColumn.add(result.getPValue());
	colocValueColumn.add(result.getColocValue());
	colocArrayColumn.add(result.getColocValuesArray());
}
 
Example #4
Source File: CachedOpEnvironment.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets the given {@link Op} instance's argument value, starting at the
 * specified offset.
 */
private Object[] otherArgs(final Op op, final int offset) {
	final CommandInfo cInfo = info(op).cInfo();
	final Module module = cInfo.createModule(op);
	final ArrayList<Object> args = new ArrayList<>();
	int i = 0;
	for (final ModuleItem<?> input : cInfo.inputs()) {
		if (i++ >= offset) args.add(input.getValue(module));
	}
	return args.toArray();
}
 
Example #5
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);

}
 
Example #6
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends RealType<T>> void
	assertDefaultInvertMinMaxProvided(final Img<T> in, final Img<T> out,
		final T min, final T max)
{

	final Op op = ops.op(Ops.Image.Invert.class, out, in, (min), (max));
	assertSame(InvertII.class, op.getClass());
	op.run();

	defaultCompare(in, out, min, max);
}
 
Example #7
Source File: SpecialOp.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static List<OpCandidate> candidates(final OpEnvironment ops,
	final String name, final Class<? extends Op> opType, final int arity,
	final Flavor flavor)
{
	// look up matching candidates
	final List<Class<?>> types = new ArrayList<>();
	if (opType != null) types.add(opType);
	if (flavor == Flavor.COMPUTER) types.add(NullaryComputerOp.class);
	else if (flavor == Flavor.FUNCTION) types.add(NullaryFunctionOp.class);
	else if (flavor == Flavor.INPLACE) types.add(UnaryInplaceOp.class);
	final OpRef ref = new OpRef(name, types, null);
	return filterArity(ops.matcher().findCandidates(ops, ref), arity);
}
 
Example #8
Source File: RTs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <I, O extends RealType<O>> UnaryComputerOp<I, O> computer(
	final OpEnvironment ops, final Class<? extends Op> opType, final I in,
	final Object... otherArgs)
{
	return (UnaryComputerOp) Computers.unary(ops, opType, RealType.class, in, otherArgs);
}
 
Example #9
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #10
Source File: RTs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <I, O extends RealType<O>> UnaryHybridCF<I, O> hybrid(
	final OpEnvironment ops, final Class<? extends Op> opType, final I in,
	final Object... otherArgs)
{
	return (UnaryHybridCF) Hybrids.unaryCF(ops, opType, RealType.class, in, otherArgs);
}
 
Example #11
Source File: MapTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testIICellImg() {
	final Img<ByteType> in = generateByteTestCellImg(true, 40, 20);

	final Op nullary = Computers.nullary(ops, Ops.Math.Zero.class,
		ByteType.class);
	ops.run(MapNullaryII.class, in, nullary);

	for (final ByteType ps : in)
		assertEquals(ps.get(), 0);
}
 
Example #12
Source File: RTs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <I1, I2, O extends RealType<O>> BinaryComputerOp<I1, I2, O>
	binaryComputer(final OpEnvironment ops, final Class<? extends Op> opType,
		final I1 in1, final I2 in2, final Object... otherArgs)
{
	return (BinaryComputerOp) Computers.binary(ops, opType, RealType.class, in1,
		in2, otherArgs);
}
 
Example #13
Source File: RTs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <I1, I2, O extends RealType<O>> BinaryFunctionOp<I1, I2, O>
	binaryFunction(final OpEnvironment ops, final Class<? extends Op> opType,
		final I1 in1, I2 in2, final Object... otherArgs)
{
	return (BinaryFunctionOp) Functions.binary(ops, opType, RealType.class, in1,
		in2, otherArgs);
}
 
Example #14
Source File: RTs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <I1, I2, O extends RealType<O>> BinaryHybridCF<I1, I2, O>
	binaryHybrid(final OpEnvironment ops, final Class<? extends Op> opType,
		final I1 in1, I2 in2, final Object... otherArgs)
{
	return (BinaryHybridCF) Hybrids.binaryCF(ops, opType, RealType.class, in1, in2,
		otherArgs);
}
 
Example #15
Source File: IIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> UnaryComputerOp<IterableInterval<T>, IterableInterval<T>>
	computer(final OpEnvironment ops, final Class<? extends Op> opType,
		final IterableInterval<T> in, final Object... otherArgs)
{
	return (UnaryComputerOp) Computers.unary(ops, opType,
		IterableInterval.class, in == null ? IterableInterval.class : in,
		otherArgs);
}
 
Example #16
Source File: GlobalThresholder.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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});
}
 
Example #17
Source File: IIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> UnaryHybridCF<IterableInterval<T>, IterableInterval<T>>
	hybrid(final OpEnvironment ops, final Class<? extends Op> opType,
		final IterableInterval<T> in, final Object... otherArgs)
{
	return (UnaryHybridCF) Hybrids.unaryCF(ops, opType, IterableInterval.class,
		in == null ? IterableInterval.class : in, otherArgs);
}
 
Example #18
Source File: JoinTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testJoinInplaceAndComputer() {
	final Op op =
		ops.op(DefaultJoinInplaceAndComputer.class, out, in, inplaceOp,
			computerOp);
	op.run();

	// test
	final Cursor<ByteType> c = out.cursor();

	while (c.hasNext()) {
		assertEquals(2, c.next().get());
	}
}
 
Example #19
Source File: IIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T>
	BinaryComputerOp<IterableInterval<T>, IterableInterval<T>, IterableInterval<T>>
	binaryComputer(final OpEnvironment ops, final Class<? extends Op> opType,
		final IterableInterval<T> in1, final IterableInterval<T> in2,
		final Object... otherArgs)
{
	return (BinaryComputerOp) Computers.binary(ops, opType,
		IterableInterval.class, in1, in2, otherArgs);
}
 
Example #20
Source File: IIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T>
	BinaryFunctionOp<IterableInterval<T>, IterableInterval<T>, IterableInterval<T>>
	binaryFunction(final OpEnvironment ops, final Class<? extends Op> opType,
		final IterableInterval<T> in1, final IterableInterval<T> in2,
		final Object... otherArgs)
{
	return (BinaryFunctionOp) Functions.binary(ops, opType,
		IterableInterval.class, in1, in2, otherArgs);
}
 
Example #21
Source File: JoinTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testJoinComputerAndInplace() {
	final Op op =
		ops.op(DefaultJoinComputerAndInplace.class, out, in, computerOp,
			inplaceOp);
	op.run();

	// test
	final Cursor<ByteType> c = out.cursor();

	while (c.hasNext()) {
		assertEquals(2, c.next().get());
	}
}
 
Example #22
Source File: RAIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> UnaryComputerOp<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>> computer(
		final OpEnvironment ops, final Class<? extends Op> opType, final RandomAccessibleInterval<T> in,
		final Object... otherArgs) {
	return (UnaryComputerOp) Computers.unary(ops, opType, RandomAccessibleInterval.class,
			in == null ? RandomAccessibleInterval.class : in, otherArgs);
}
 
Example #23
Source File: RAIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T, F> UnaryComputerOp<RandomAccessibleInterval<T>, RandomAccessibleInterval<F>> computer(
		final OpEnvironment ops, final Class<? extends Op> opType, final RandomAccessibleInterval<F> out,
		final RandomAccessibleInterval<T> in, final Object... otherArgs) {
	return (UnaryComputerOp) Computers.unary(ops, opType, out == null ? RandomAccessibleInterval.class : out,
			RandomAccessibleInterval.class, in == null ? RandomAccessibleInterval.class : in, otherArgs);
}
 
Example #24
Source File: RAIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> UnaryFunctionOp<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>> function(
		final OpEnvironment ops, final Class<? extends Op> opType, final RandomAccessibleInterval<T> in,
		final Object... otherArgs) {
	return (UnaryFunctionOp) Functions.unary(ops, opType, RandomAccessibleInterval.class,
			in == null ? RandomAccessibleInterval.class : in, otherArgs);
}
 
Example #25
Source File: RAIs.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> UnaryHybridCF<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>> hybrid(
		final OpEnvironment ops, final Class<? extends Op> opType, final RandomAccessibleInterval<T> in,
		final Object... otherArgs) {
	return (UnaryHybridCF) Hybrids.unaryCF(ops, opType, RandomAccessibleInterval.class,
			in == null ? RandomAccessibleInterval.class : in, otherArgs);
}
 
Example #26
Source File: MapNeighborhoodTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
@Ignore("There is no way to throw an error for invalid typed computers at the moment.")
public
	void testMapNeighoodsWrongArgs() {
	final Op mapOp =
		ops.op(DefaultMapNeighborhood.class, out, in,
			new RectangleShape(1, false), new Increment());

	// ClassCastException will be thrown
	mapOp.run();
}
 
Example #27
Source File: MapNeighborhoodTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Test if every neighborhood pixel of the image was really accessed during
 * the map operation.
 *
 * @see DefaultMapNeighborhood
 */
@Test
public void testMapNeighborhoodsAccess() {
	final Op mapOp =
		ops.op(DefaultMapNeighborhood.class, out, in,
			new RectangleShape(1, false), new CountNeighbors());
	mapOp.run();

	for (final ByteType t : out) {
		assertEquals(9, t.get());
	}
}
 
Example #28
Source File: AddNumericTypeBinaryMathAddTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testAdd() {
	final ARGBDoubleType a = new ARGBDoubleType(255, 128, 128, 128);
	final ARGBDoubleType b = new ARGBDoubleType(255, 75, 35, 45);
	final Op op = ops.op(Ops.Math.Add.class, a, a, b);
	assertSame(NumericTypeBinaryMath.Add.class, op.getClass());

	op.run();
	assertEquals(203.0, a.getR(), DELTA);
	assertEquals(163.0, a.getG(), DELTA);
	assertEquals(173.0, a.getB(), DELTA);
}
 
Example #29
Source File: MapTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testIterable() {
	final Img<ByteType> in = generateByteArrayTestImg(true, 10, 10);

	final Op nullary = Computers.nullary(ops, Ops.Math.Zero.class,
		ByteType.class);
	ops.run(MapNullaryIterable.class, in, nullary);

	for (final ByteType ps : in)
		assertEquals(ps.get(), 0);
}
 
Example #30
Source File: MapTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testII() {
	final Img<ByteType> in = generateByteArrayTestImg(true, 10, 10);

	final Op nullary = Computers.nullary(ops, Ops.Math.Zero.class,
		ByteType.class);
	ops.run(MapNullaryII.class, in, nullary);

	for (final ByteType ps : in)
		assertEquals(ps.get(), 0);
}