Problem: macro not saving files
Posted by cnarciso on Feb 11, 2014; 4:52pm
URL: http://imagej.273.s1.nabble.com/Problem-macro-not-saving-files-tp5006489.html
Essentially, I recently wrote a stitching macro which will batch stitch individual image z-stack tiles into mosaics and sort those mosaics into folders by sample and channel (this part is working fine). The only problem is that the stitching plugin, when saving-to-disc, saves the samples as individual .tif files for each z-slice in a stack, rather than saving them as stacks. This is annoying when trying to open the stitched files for analysis or running further image processing on them. So I am trying to write a macro which I can run after my stitching macro that will access the folders created during stitching for each channel and import all the images as a stack, then save the stack to the disc. I can then delete the 121 individual panels*channels*samples created by stitching for ONE image stack per sample.
I am trying to do this with "Import">"Image sequence" then "Save as." I tested the process manually for one sample and it works fine, but when I try to incorporate this into a macro, it does not save the file and I cannot figure out why it will not. I have tried running both with and without batch mode on, and it makes no difference. The code is pasted below. Anyone see any obvious errors or have any ideas on what might be going wrong here?
(And, yes, I have double and triple-checked the directory names are correct. In fact, I c/p all of that from the other macro just to make sure there were no typing errors...)
Many thanks!
Macro Code:
\\setBatchMode(true);
dir1 = getDirectory("Choose Source Directory");
Dialog.create("Parameters");
Dialog.addNumber("# Embryos", 26);
Dialog.addNumber("Z-Planes", 121);
Dialog.show();
emb = Dialog.getNumber();
z = Dialog.getNumber();
c=1;
for (i=1; i<emb+1; i++) {
embdir=dir1+File.separator+"Embryo_"+c+"";
dir488 = embdir+File.separator+"488";
dir647 = embdir+File.separator+"647";
dir405 = embdir+File.separator+"405";
fn488=embdir+File.separator+"488_"+c+".tif";
fn647=embdir+File.separator+"647_"+c+".tif";
fn405=embdir+File.separator+"405_"+c+".tif";
run("Image Sequence...", "open=&dir488 number=&z starting=1 increment=1 scale=100 sort");
saveAs("Tiff", "&fn488");
close();
run("Image Sequence...", "open=&dir647 number=&z starting=1 increment=1 scale=100 sort");
saveAs("Tiff", "&fn647");
close();
run("Image Sequence...", "open=&dir405 number=&z starting=1 increment=1 scale=100 sort");
saveAs("Tiff", "&fn405")
close();
c++;
}