imagej / imagej-legacy

ImageJ+ImageJ2 compatibility layer
https://imagej.net/libs/imagej-legacy
BSD 2-Clause "Simplified" License
17 stars 25 forks source link

Scripts calling IJ1 plugins can fail on ImageStack.getProcessor upon second run #240

Open imagejan opened 4 years ago

imagejan commented 4 years ago

See this forum topic.


While the following (Groovy) script works:

import ij.IJ
import ij.plugin.RGBStackMerge
import ij.ImagePlus

imp1 = IJ.createImage("Red", "8-bit white", 100, 100, 1);
imp2 = IJ.createImage("Green", "8-bit black", 100, 100, 1);
imp3 = IJ.createImage("Blue", "8-bit ramp", 100, 100, 1);

impResult = RGBStackMerge.mergeChannels([imp1, imp2, imp3] as ImagePlus[], false)

It doesn't work if you split it into two parts:

#@output imp1
#@output imp2
#@output imp3

import ij.IJ

imp1 = IJ.createImage("Red", "8-bit white", 100, 100, 1);
imp2 = IJ.createImage("Green", "8-bit black", 100, 100, 1);
imp3 = IJ.createImage("Blue", "8-bit ramp", 100, 100, 1);

and

#@ ImagePlus imp1
#@ ImagePlus imp2
#@ ImagePlus imp3

import ij.plugin.RGBStackMerge
import ij.ImagePlus

impResult = RGBStackMerge.mergeChannels([imp1, imp2, imp3] as ImagePlus[], false)

The second part will run the first time, but fail on subsequent attempts with the following exception:

java.lang.IllegalArgumentException: Argument out of range: 1
    at ij.ImageStack.getProcessor(ImageStack.java:276)
    at ij.plugin.RGBStackMerge.mergeHyperstacks(RGBStackMerge.java:300)
    at ij.plugin.RGBStackMerge.mergeChannels(RGBStackMerge.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at Script34.run(Script34.groovy:8)
    at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:303)
    at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:122)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$20(DefaultThreadService.java:228)
    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:748)