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

imagej-ops
Tags: #<Tag:0x00007fb883fdfa78>

#1

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,
John

Ps, ya, i know Erode is a AbstractBinaryHybridCF

Some failed attempts:

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

caused

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

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 );
op.initialize();
op.calculate();

though that yields:

Caused by: java.lang.NullPointerException
    at net.imagej.ops.special.SpecialOp.op(SpecialOp.java:309)
    at net.imagej.ops.special.computer.Computers.unary(Computers.java:177)
    at net.imagej.ops.morphology.erode.DefaultErode.initialize(DefaultErode.java:105)
    at net.imglib2.cache.exampleOps.ExampleOps$OpLoader.get(ExampleOps.java:142)
    at net.imglib2.cache.exampleOps.ExampleOps$OpLoader.get(ExampleOps.java:1)

and here’s where I got stuck


#2

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:

Cheers,

Christian


#3

@dietzc,

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!

John