imagej / imagej-ops

ImageJ Ops: "Write once, run anywhere" image processing
https://imagej.net/libs/imagej-ops
BSD 2-Clause "Simplified" License
88 stars 42 forks source link

SobelRAI derivativeComputer array error prone if dimension mismatch #627

Open gselzer opened 4 years ago

gselzer commented 4 years ago

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...

imagesc-bot commented 4 years ago

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

ctr26 commented 4 years ago

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

gselzer commented 4 years ago

@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

ctr26 commented 4 years ago

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")
gselzer commented 4 years ago

@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.