Repository navigation
Closed
Description
While testing SciJavaOps in the Fiji script editor (using Jython) I discovered that I was unable to use the "math.subtract" op to subtract two images from each other.
Here is a minimal example you can run with an open 2D image in Fiji:
#@ Img img_in
# get op environoment
from org.scijava.ops.api import OpEnvironment
ops = OpEnvironment.getEnvironment()
# create gauss blur of image
gauss = ops.op("filter.gauss").arity2().input(img_in, 3.0).apply()
# subtract gauss blur from input image
res = ops.op("math.subtract").arity2().input(img_in, gauss).apply()This produces the following output:
...
... 24 more
Suppressed: org.scijava.ops.api.features.OpMatchingException: No matching 'math.subtract/java.util.function.BiFunction<net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>, net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>, java.lang.Object>' op
Request:
- Name: "math.subtract", Types: java.util.function.BiFunction<net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>, net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>, java.lang.Object>
Input Types:
* net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>
* net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>
Output Type:
* java.lang.Object
Candidates:
- No candidates found!
at org.scijava.ops.api.features.MatchingResult.singleMatch(MatchingResult.java:67)
at org.scijava.ops.engine.matcher.impl.RuntimeSafeMatchingRoutine.findMatch(RuntimeSafeMatchingRoutine.java:60)
at org.scijava.ops.api.features.MatchingRoutine.match(MatchingRoutine.java:43)
at org.scijava.ops.engine.matcher.impl.DefaultOpMatcher.match(DefaultOpMatcher.java:66)
... 36 more
Suppressed: org.scijava.ops.api.features.OpMatchingException: Unable to find an Op adaptation for org.scijava.ops.api.features.MatchingConditions@14eb64f2
at org.scijava.ops.engine.matcher.adapt.AdaptationMatchingRoutine.findMatch(AdaptationMatchingRoutine.java:157)
at org.scijava.ops.api.features.MatchingRoutine.match(MatchingRoutine.java:43)
at org.scijava.ops.engine.matcher.impl.DefaultOpMatcher.match(DefaultOpMatcher.java:66)
... 36 more
Suppressed: org.scijava.ops.api.features.OpMatchingException: No matching 'math.subtract/java.util.function.BiFunction<net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>, net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>, java.lang.Object>' op
Request:
- Name: "math.subtract", Types: java.util.function.BiFunction<net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>, net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>, java.lang.Object>
Input Types:
* net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>
* net.imagej.ImgPlus<net.imglib2.type.numeric.integer.UnsignedShortType>
Output Type:
* java.lang.Object
Candidates:
- No candidates found!
at org.scijava.ops.api.features.MatchingResult.singleMatch(MatchingResult.java:67)
at org.scijava.ops.engine.matcher.impl.RuntimeSafeMatchingRoutine.findMatch(RuntimeSafeMatchingRoutine.java:60)
at org.scijava.ops.api.features.MatchingRoutine.match(MatchingRoutine.java:43)
at org.scijava.ops.engine.matcher.impl.DefaultOpMatcher.match(DefaultOpMatcher.java:66)
... 36 moreReacted by Gabriel Selzer
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
hinerm commentedon Sep 26, 2023
Our theory was that the problem was that the output type of
java.lang.Objectprevented lifters from matching to raise pixel-wise subtracts to work on these images.I tested this with the following in Java:
But it produces the same exception:
I will try to investigate further to determine the root cause of the failure here.
elevans commentedon Sep 28, 2023
I don't know if this helps but
ops.op("convert.float32")also errors out the same way when using it from Jython:Produces this stack trace:
I also tried creating an output image for the op to see if that helped...it did not:
hinerm commentedon Sep 28, 2023
@elevans Currently I wouldn't expect Functions operating on images to work. Most algorithms are implemented as Computers on single types - they can be lifted to work on Images or adapted to Functions, but currently not both (required to match a Function Op that operates on Images). Let me know if that doesn't make sense.
hinerm commentedon Sep 29, 2023
I have outlined the problems and started exploring solutions on this branch.
What I see as needing to happen:
IandImg<I>, for computers and functions (e.g. somath.add(Img, 5)works)IandImg<I>, for compters and functions (e.g. somath.addcan be called as aComputeror aFunction)hinerm commentedon Nov 13, 2023
OK I thought I was done working on https://github.com/scijava/incubator/tree/imagej/imagej-ops2/convert-common-image-types
But matches like this with no
outTypespecified don't work:I suspect they have to work because trying to make a
Nil<Img<IntType>>is probably a nightmare in python? Does that intuition seem correct @elevans?@gselzer any thoughts off the top of your head on why matching without an
outTypedoesn't work, but with anoutTypedoes?gselzer commentedon Nov 13, 2023
@hinerm you're trying to look for a
BiFunction<Img<IntType>, IntType, Object>. I'm guessing none exist, so it tries to adapt something. Adaptation toFunctions with anObjectoutput is super tricky.You're probably trying use this adapt Op, right? The second Op dependency is then maybe this guy, and that guy will need some
Function<RAII, RAIO>creator - I'm guessing that can't be found because thatOtype is vacuous, since it's all coming from thatObjectoutput type.hinerm commentedon Nov 13, 2023
@gselzer How devastating would it be for a match request with unspecified output to behave like matching an
Anyinstead ofObject? I feel like that is closer to the semantic meaning of leaving off output specification right?gselzer commentedon Nov 13, 2023
You're right, I agree
Anyis better, although there may be some fun casting involved. I think it's worth a try...Merge branch 'imagej/imagej-ops2/convert-common-image-types' into main
Merge pull request #134 from scijava/scijava-ops-engine/cache-hint