Getting an instance of an "Op" (AbstractBinaryHybridCF) object

Tags: #<Tag:0x00007fb883fdfa78>


To you ops-gurus out there,

Today, with @tpietzsch, @axtimwalde, @hanslovsky et al, we wanted to write some method that would:

  1. Take some op as an argument
  2. Apply that op to some input
  3. and do something with the result

more specifically, something like:

RandomAccessibleInterval<T> input;
AbstractUnaryHybridCF<RandomAccessibleInterval< T >, IterableInterval<T>> op;
IterableInterval< T > output;
// ...
// grab an input and output
op.compute( input, output );  // run that op somehow
// do something with output
// ...

In a setup like the above, we’d like an instance of AbstractUnaryHybridCF, but it’s not clear how to get one.

To be concrete, say I want a DefaultErode. I see how I can apply it with something like
ij.op().morphology().dilate( ... ), but not how to get a DefaultErode object. See some attempts below.

ij.op().run( "<name>", ...) seems like a possibility, but there are strings there that would correspond to ops that may not work with the inputs we give.

Thanks for the help,

Ps, ya, i know Erode is a AbstractBinaryHybridCF

Some failed attempts:

op = new DefaultErode<UnsignedShortType>();
op.compute(  Views.interval( source, output ) , shape, output )


Caused by: java.lang.NullPointerException
    at net.imagej.ops.morphology.erode.DefaultErode.compute(
    at net.imglib2.cache.exampleOps.ExampleOps$OpLoader.get(
    at net.imglib2.cache.exampleOps.ExampleOps$OpLoader.get(

Ya, the default constructor does nothing…then I saw the initialize method and tried:

op = new DefaultErode<UnsignedShortType>();
op.setInput1( Views.interval( source, output ) );
op.setInput2( shape );
op.setOutput( output );

though that yields:

Caused by: java.lang.NullPointerException
    at net.imagej.ops.special.SpecialOp.op(
    at net.imagej.ops.morphology.erode.DefaultErode.initialize(
    at net.imglib2.cache.exampleOps.ExampleOps$OpLoader.get(
    at net.imglib2.cache.exampleOps.ExampleOps$OpLoader.get(

and here’s where I got stuck


Hiho @bogovicj,

I’d always suggest to use Computer.unary(...) or Function.unary(...) in order to get a Computer or Function. Is there a particular reason you really want to have a AbstractUnaryHybridCF? I guess you use it as a Computer, right?

Something like Computers.unary(ops, DefaultErode.class, RandomAccessibleInterval.class, in, shape, false) should work, where e.g. Shape shape; and RandomAccessibleInterval<ByteType> in;.

Let me know if it worked. If not, we’ll figure it out :+1:





No particular reason for AbstractUnaryHybridCFComputer looks like the way to go.
I’ll try that out, thanks for the pointer!

Follow up: this is great. Thanks again!