Problem: macro not saving files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem: macro not saving files

cnarciso
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++;

}  
Reply | Threaded
Open this post in threaded view
|

Re: Problem: macro not saving files

cnarciso
SOLVED:

Basically for the "Save as..." you do not concatenate the variable or put it in parenthesis...

so...

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();

works like a charm.
Reply | Threaded
Open this post in threaded view
|

Re: Problem: macro not saving files

Michael Schmid
In reply to this post by cnarciso
Hi Cnarciso,

if your variable is 'fn488', it should be
  saveAs("tiff", fn488);

'saveAs' is a macro function that takes String variables or String constants as arguments.

The notation '&variableName' is only for the options of 'run(command, options)', e.g.
  run("My Custom Filesave Plugin",  "save=&myPath quality=&myQualityVariable");

Michael
________________________________________________________________
On Feb 11, 2014, at 17:52, cnarciso wrote:

> 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++;
>
> }  
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Problem-macro-not-saving-files-tp5006489.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html