imagej-ops icon indicating copy to clipboard operation
imagej-ops copied to clipboard

SobelRAI derivativeComputer array error prone if dimension mismatch

Open gselzer opened this issue 5 years ago • 5 comments

As I discovered by trying to solve a post on forum.image.sc, SobelRAI can throw ArrayIndexOutOfBoundsExceptions if the input image differs on the number of dimensions from what was passed to the matcher during the creation of the Op. The faulty line is here: if the input image has fewer dimensions than the image passed during creation, we will receive an ArrayIndexOutOfBoundsException in that for loop, and if we have more dimensions than we had during Op creation, then not all dimensions of the image will be processed.

Is there any reason that we do not run a for loop on all dimensions of the image and use only one derivativeComputer? We could just transform the dimensions of the image to compute every dimension...

gselzer avatar Jun 08 '20 13:06 gselzer

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/slice-wise-sobel-using-ops/38720/2

imagesc-bot avatar Jun 08 '20 13:06 imagesc-bot

I think Gauss and derivative Gauss also have the same behaviour btw.

ctr26 avatar Jun 08 '20 14:06 ctr26

@ctr26 can you be more specific in which Ops have the issue?

I am only seeing this issue in PartialDerivativesRAI. I am not seeing this issue in any of the Gauss ops

gselzer avatar Jun 08 '20 14:06 gselzer

This fails for me:

#@ Dataset data
#@OUTPUT Dataset output
#@ OpService ops
#@ DatasetService ds

from net.imagej.axis import Axes
converted = ops.convert().float32(data.getImgPlus())

dog = ops.create().img(converted)

converted_in = ops.transform().flatIterableView(converted)
converted_out = ops.transform().flatIterableView(dog)

#dog_op = ops.op("filter.dog", converted_in,1,1)
#dog_op = ops.op("filter.sobel", converted_in)
dog_op = ops.op("filter.derivativeGauss", converted_in,1,1)

t_dim = data.dimensionIndex(Axes.TIME)
fixed_axis = [d for d in range(0, data.numDimensions()) if d != t_dim]

ops.slice(converted_out,converted_in, dog_op, fixed_axis)

output = ds.create(converted_out)
print("success")

ctr26 avatar Jun 08 '20 14:06 ctr26

@ctr26 that is failing for other reasons. Check the agreement of the arguments you are passing with the parameters of the Op (forum.image.sc is the place to discuss this). If you find any Ops that are experiencing the same issue that we are seeing with SobelRAI and PartialDerivativesRAI (within this code base), this would be the place to report it.

gselzer avatar Jun 08 '20 14:06 gselzer