I have several image stacks from a confocal microscope saved as .lsm, and I want to write a macro that:
- opens an image in a folder
- Makes a Composite, then Stacks to RGB, then sets animation options
- Saves this as an Animated Gif to another folder
What I made so far:
function stack_to_gif(input, output, filename, fps) {
open(input + filename);
run("Make Composite");
run("Stack to RGB", "slices");
run("Animation Options...", "speed=fps");
run("Animated Gif ... ", "name=title=[Do not use] optional=[] " +
"image=[No Disposal] set=500 number=-1 transparency=[No Transparency] " +
"red=0 green=0 blue=0 index=0 filename=output+filename");
saveAs("Animated Gif...", output+filename);
close();
}
inputDir=getDirectory("Choose an input location");
outputDir=getDirectory("Choose an output location");
fps=120;
setBatchMode(true);
list = getFileList(inputDir);
for (i = 0; i < list.length; i++){
stack_to_gif(inputDir, outputDir, list[i], fps);
}
setBatchMode(false);
I know that the two bottom parts work as I use them in another macro, too.
My problem is with the saveAs("Animated Gif...") part, as it does not allow me to save the RGB-types, even though it works when I do it manually.
What I tried so far:
- use the same options of run("Animated Gifs...") within saveAs("Animated Gifs...")
- use one or the other but not both
- use run("8-bit"); after Animation Options, which works (but I lose the colors)
What irks me is that it works perfectly fine when I do it manually, but I get the error message
To save as Animated GIF, the stack must be converted to 8-bit indexed color by the Image>Type>8-bit Color command.
and I don't know why this doesn't happen when I do it myself.
Thank you for your help.