Save As Image Sequence using slice labels as file names fails

imagej
image-sequence

#1

Hi,

I have a series of single channel time laps images (example download, 115 MB) that I import as “Image Sequence” to process them as one stack.

After processing, I wish to save them in exactly the same sequence as they were opened, using the same name.

My simple approach was to use the “Save As > Image Sequence” function again and activate the option “use slice labels as file names”, see code below.

I receive indeed the same number of images with the correct name, and the imageJ status bar also indicates that every slice is written.
The finale images are however corrupt and 0 kb in size.

Here is a simplified imageJ macro to reproduce the issue:

run("Image Sequence...", "open=D:/path/to/source/ file=Air sort");
// potential processing is happening here
run("Image Sequence... ", "format=TIFF use save=D:/path/to/target/");

Is “Save As Image Sequence” maybe not intended to split into stacks this way?


#2

Indeed, it might not have been intended to respect the slice indices (:1, :2, etc.) generated by the Import > Image Sequence… and be smart enough to append slices to the same stack when saving.

The problematic part of the slice label is the colon (:) in this case. When replacing the colon by e.g. a dash, saving works as expected:

run("Image Sequence...", "open=D:/path/to/source/ file=Air sort");
// potential processing is happening here

// Sanitize slice labels
for (i = 1; i <= nSlices; i++) {
  setSlice(i);
  label = replace(getMetadata("Label"), ":", "-");
  setMetadata("Label", label);
}

run("Image Sequence... ", "format=TIFF use save=D:/path/to/target/");

This ends up with a single tif file for each slice of each input stack, which might not be what you intended to do. If you want to batch process a list of stacks, I’d recommend against using Image Sequence and instead use one of the other Batch Processing options.