Image sequence with different sizes



Hi all,

I’m trying to import an image sequence of multiple files in a folder with different sizes. Is it possible to still open them ?



Good day,

afaik, in plain ImageJ not as a sequence!

You may open single images and adapt their canvas to create images of equal size.




The problem is that the 1st step of the pipeline is using the Grid stitching plugin and letting it calculate the overlap. Meaning that from experiment and even from timepoints, the canvas is different and can’t really be known previously :confused:

I already tried to crop and thought it would be enough but apparently not.


Does your stitching algorithm work with an image sequence only?

No clue



In the beginning all the images are the same size but the calculated overlap makes the result of the stitching a different size.

Opening them as image sequence would be for a next step.

Thansk anyway :slight_smile:


Hi @lguerard,

ImageJ2 should be able do this without too much trouble, though it’ll take some scripting.
I’ll have a crack at this later, unless someone beats me to it.



Hi @bogovicj

Thanks, that would be awesome ! :slight_smile:. I’ll be waiting then, there’s no (immediate) rush !


Hi @lguerard,

This script should do the trick:

It works on all the images that are currently open, and assumes the images are 3d.
If they’re 2d just delete these lines:

// set the axis labels

If they’re 4-or-higher-D, then this probably wont work and will need some fiddling.

Let us know how it goes,


Hi @bogovicj,

Thanks for the help ! I was looking at opening them as image sequence but maybe opening them first then making a stack is indeed better. I’ll try that and let you know ! :slight_smile:


I get this error when running the script:

Started concatOpenImages.groovy at Tue Aug 21 16:13:23 CEST 2018
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script4.groovy: 47: unexpected token: ui @ line 47, column 1. resdata );

Any ideas?


You seem to be running a slightly different version of what @bogovicj posted above: his script has only 46 lines, while your error message is from line 47. Please have a look if your first line really looks like this:

// @UIService ui

This line is a script parameter input and is required for the variable ui to mean anything in your code.


I uncommented that line after the script wouldn’t run in its untouched form.

Right now, I’m trying to run this exactly:

//@UIService ui
//@ImageDisplayService disp
//@DatasetService data
//@LogService log

import java.util.ArrayList;

import net.imagej.axis.Axes

import net.imglib2.view.Views;
import net.imglib2.util.Intervals;
import net.imglib2.util.Util; data.getDatasets( disp.getActiveImageDisplay()))

datasets = data.getDatasets()
if( datasets.size() == 0 )
	ui.showDialog("No images found")

 * the size of the output will be the union
 * of the input sizes
total_interval = datasets.get( 0 )
for( d in datasets )
	total_interval = Intervals.union( total_interval, d )

exp_imgs = new ArrayList();
for( d in datasets )
	exp_imgs.add( Views.interval( Views.extendZero( d ), total_interval))

resdata = data.create( Views.stack( exp_imgs )

// uncomment for 3D images
//// set the axis labels
//resdata.axis(3).setType(Axes.TIME) resdata );

But I still get the same error.


You’re missing a closing parenthesis here that’s present in the original script.


That’s my bad actually. Just updated the script a few minutes ago.

Thanks for catching this @imagejan


Oh, I see :slight_smile: (I should have checked the revisions before replying ;-))


Thank you, bogovicj!