"Images to Stack" command as an ImageJ Op?



Hi all,

Is there an ImageJ Op for the “Images to Stack” command, specifically with the “Copy (center)” method to handle images of different sizes? I couldn’t find anything using the ImageJ2 “Find Commands” plugin or by searching and figured I ought to ask here before re-inventing the wheel.

If it doesn’t exist, I’d like to get some input to avoid re-inventing other wheels also. Excuse me for the barrage of questions - I’m somewhat new to the ImageJ2 architecture and ecosystem and still don’t quite understand how the parts interact. If there are any high-level diagrams to explain things, please point me at them!

  1. “Images to Stack” requires an arbitrary number of input images and the IJ1 command does this using pattern matching on the titles of all open images. This is a very crude approach and doesn’t really fit in with the IJ2 way of doing things. However, what is the IJ2 way to approach this? SciJava @Parameter doesn’t (currently) support an arbitrary number of images as input, e.g., a Dataset parameter.

  2. In order to add support for a Dataset parameter, is it just a matter of implementing a new InputWidget, WidgetModel and UIComponent, or are there a number of other things to consider? Is there any documentation (other than the source code) on how to go about this?

  3. Would arrays of parameters like this work with input harvesting for macros and headless usage? I’m not at all familiar with how those systems work.



Hi @omaraa

So. I cannot help you too much in Ops details… But, there is now an Op Finder in ImageJ - so you can search for existing Ops there. Just type ‘Find Ops’ into the Command Finder …

I’ll leave other Ops experts to answer your other questions …



Hi @omaraa,

I’ll try to help you… however I’m not sure if I understand each detail of your question… so correct me if I’m wrong!

If I understand you correctly, you have several images in n-d and you want to combine them to an n+1-d image, in your case 2d planes to a 3d stack? Are you already working with imglib2 (imglib2.net)? There are several nice convenience methods. The basic approach would be as follows:

  1. Take your image and extend it using Views.extend(...) or ops().transform().extend(...) or so. Basically, you take the image and extend it at the borders given some strategy (e.g. zeros, mirrored values, fade out etc…).
  2. Basically, you can now crop an arbitrary Interval from the result of the extend using e.g. Views.interval or ops().transform().interval(..). All intervals have now the same size.
  3. Using Views.stack(...) you can combine the intervals from (2).

Does this help?




So if I want to do generate such stack from various image sizes in the Jython macro language, I need to extend my images to the size of the largest image of the list before joining them into a stack object.

There is really no way to use the Images to stack method with a list of images as argument ?


The latest ImageJ daily build (1.52d16) adds a static method to the ImagesToStack class that converts an array of images into a stack. Here is a JavaScript example:

  images = new Array(3);
  images[0] = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
  images[1] = IJ.openImage("http://wsr.imagej.net/images/leaf.jpg");
  images[2] = IJ.openImage("http://wsr.imagej.net/images/boats.gif");
  stack = ImagesToStack.run(images);
  if (stack!=null)

The ImagesToStack.run(images) method uses the default settings (“copy centered”, “use titles as labels”) but it can be extended to support options if needed.

View the source code changes at