VirtualStack setProcessor at specified slice error : Argument out of range

Tags: #<Tag:0x00007fd54097a9b0>



I need to process a virtual stack with Groovy with the IJ1 library, and I have no clue why the following sample code doesn’t work:

import ij.ImageJ
import ij.IJ
import ij.ImagePlus
import ij.process.*
import ij.ImageStack
import ij.VirtualStack

w = 10
h = 15
n = 25
z = 1 // or any other value...

VirtualStack epsxx = new VirtualStack(w, h, n)
epsxx.setProcessor(new FloatProcessor(w, h), z)

I get this error:

java.lang.IllegalArgumentException: Argument out of range: 1
	at ij.ImageStack.setProcessor(
	at ij.ImageStack$setProcessor$ Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(
	at javax.script.AbstractScriptEngine.eval(Unknown Source)
	at org.scijava.thread.DefaultThreadService$
	at Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$ Source)
	at Source)

IJ.log(epsxx.toString()) returns the correct dimensions.
Is it because there is no backing storage?
Thank you for your help!


What are you trying to accomplish? VirtualStacks are read-only so it does not make sense to call setProcessor() on a VirtualStack. The latest ImageJ daily build (1.51m3) includes an example (duplicated below) that demonstrates how to use the VirtualStack(width,height,slices) constructor.

  // This script creates a virtual stack that 
  // does not use backing storage.
  gd = new GenericDialog("Text Stack");
  gd.addStringField("Title:", "1TB Virtual Stack", 15);
  gd.addNumericField("Width:", 1024, 0, 8, "");
  gd.addNumericField("Height:", 1024, 0, 8, "");
  gd.addNumericField("Slices:", 1024*1024, 0, 8, "");
  title = gd.getNextString();
  width = gd.getNextNumber();
  height = gd.getNextNumber();
  slices = gd.getNextNumber();
  stack = new VirtualStack(width,height,slices);
  new ImagePlus(title,stack).show();


Thank you for your answer.
Actually I wasn’t aware that virtual stacks are read-only (precisely because they inherit setProcessor() from ImageStack).
Basically, what I’m trying to do is to write processed images in a TIF stack sequentially without loading them into memory, and display the virtual stack at the end of the process. But I can live without that, and append the images to a TIF file on-the-fly and load it as a virtual stack when the process is done.