ijpb / MorphoLibJ

Collection of mathematical morphology methods and plugins for ImageJ
http://imagej.net/MorphoLibJ
GNU Lesser General Public License v3.0
98 stars 49 forks source link

Error when applying opening/closing with an ellipsoid structuring element #82

Closed giocard closed 1 month ago

giocard commented 5 months ago

Note: the error appears only when specifying the Ball element and for some combinations of radii (e.g. 4,4,1 or 8,8,2) I suspect that this is due to some rounding error when adding and removing the borders, but I was not able to pinpoint the piece of code.

The error can be reproduced with these two macro commands

newImage("HyperStack", "8-bit grayscale-mode", 512, 512, 1, 32, 1); run("Morphological Filters (3D)", "operation=Opening element=Ball x-radius=4 y-radius=4 z-radius=1");

The error message is

(Fiji Is Just) ImageJ 2.14.0/1.54f; Java 1.8.0_322 [64-bit]; Windows 10 10.0; 858MB of 65386MB (1%)

java.lang.IllegalArgumentException: Crop bounds exceed image bounds at inra.ijpb.shape.ImageShape.cropRect(ImageShape.java:208) at inra.ijpb.morphology.strel.AbstractStrel3D.closing(AbstractStrel3D.java:341) at inra.ijpb.morphology.filter.Closing.process(Closing.java:82) at inra.ijpb.morphology.Morphology.closing(Morphology.java:507) at inra.ijpb.morphology.Morphology$Operation.apply(Morphology.java:176) at inra.ijpb.plugins.MorphologicalFilter3DPlugin.process(MorphologicalFilter3DPlugin.java:169) at inra.ijpb.plugins.MorphologicalFilter3DPlugin.run(MorphologicalFilter3DPlugin.java:110) at ij.IJ.runUserPlugIn(IJ.java:244) at ij.IJ.runPlugIn(IJ.java:210) at ij.Executer.runCommand(Executer.java:152) at ij.Executer.run(Executer.java:67) at ij.IJ.run(IJ.java:326) at ij.IJ.run(IJ.java:337) at ij.macro.Functions.doRun(Functions.java:703) at ij.macro.Functions.doFunction(Functions.java:99) at ij.macro.Interpreter.doStatement(Interpreter.java:281) at ij.macro.Interpreter.doStatements(Interpreter.java:267) at ij.macro.Interpreter.run(Interpreter.java:163) at ij.macro.Interpreter.run(Interpreter.java:93) at ij.macro.Interpreter.run(Interpreter.java:107) at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:164) at ij.IJ.runMacro(IJ.java:165) at ij.IJ.runMacro(IJ.java:154) at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1186) at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1182) at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1133) at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1182) at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:145) at org.scijava.script.ScriptModule.run(ScriptModule.java:173) at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165) at org.scijava.module.ModuleRunner.call(ModuleRunner.java:125) at org.scijava.module.ModuleRunner.call(ModuleRunner.java:64) at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:247) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:750)

dlegland commented 5 months ago

Hi,

thanks for reporting!

It looks like a rounding error indeed! Actually, I could not reproduce, but I'm pretty sure the problem simply comes from the control that throws the exception. I try to check this more in details soon!

giocard commented 5 months ago

Hi,

thank you for looking into it. If it is of any help, I tried on two different Windows machine and on a fresh installation of Fiji, and I always get the error. I also tried previous versions of the plugin, and the error is present in 1.6.0 but not in 1.5.0 (as packaged in sites.imagej.net)

dlegland commented 5 months ago

Hi,

I found a mistake in the way the "offset" of the structuring element was computed. I fixed it in https://github.com/ijpb/MorphoLibJ/commit/355b6c8f54f6449d75d1c6595309e981c2226357, this made the bug disappear for me (I could finally reproduce on another computer).

giocard commented 5 months ago

Great! Thank you very much.