Summarize table not writing in macro

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

Summarize table not writing in macro

schamber789
Hello all,

I have this macro below that works fine on a single image, but doesn't work
in batch mode. I want to use the macro to process a single folder at a time
of images with .zvi extension.  I'd appreciate any guidance on where to
look for the problem!

Thanks!
Scott Chamberlain
Simon Fraser University

macro "countem [q]" {
   title = getTitle;
   input = "/path1/";
   output = "/path2/";

    function doit(input, output, title) {
       run("ZVI Reader", "open="+intput+title)
       run("Subtract Background...", "rolling=100");
       run("Invert");
       setAutoThreshold("Yen");
       run("Convert to Mask");
       run("Watershed");
       run("Set Measurements...", "slice area count mean circularity
redirect=None");
       run("Analyze Particles...", "size=40-120 circularity=0.50-1.00
show=summarize");
       saveAs("text", output+title+".txt");
       close();
     }

   setBatchMode(true);
   list = getFileList(input);
   for (i = 0; i < list.length; i++)
        doit(input, output, list[i]);
   setBatchMode(false);
}

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Summarize table not writing in macro

Christine Labno-2
Hi Scott,

Since you asked for guidance, here are a couple of suggestions, followed by a whole batch process macro based on your code that runs and creates a summary table for me on some test images.  Full disclosure, I am being a bit lazy and just using a folder full of tif files, so I can't comment on any problems with the .zvi file opener.  

>On Friday, September 20, 2013 9:04 PM Scott Chamberlain wrote:
>Subject: Summarize table not writing in macro

>Hello all,

>I have this macro below that works fine on a single image, but doesn't work
>in batch mode. I want to use the macro to process a single folder at a time
>of images with .zvi extension.  I'd appreciate any guidance on where to
>look for the problem!

>Thanks!
>Scott Chamberlain
>Simon Fraser University

>macro "countem [q]" {
>   title = getTitle;

If you are in batch mode, there won't be a file open at this point, so there isn't a way to get a title from it.  Best to move this downstream a little.

>   input = "/path1/";
 >  output = "/path2/";

The way this is written I'm assuming you want to "hard code" in your filepaths.  This is a totally valid.  You could also choose to go with

        input = getDirectory("Choose a Directory to PROCESS");    
     list = getFileList(input);                                                                                                
output = getDirectory("Choose a Directory for SAVING");

to make the macro a little more flexible.  This will direct the user (you) to click a folder to process and another to save to each time the macro is run.  This way you won't have to modify the code for each run.  It's up to you.  

>    function doit(input, output, title) {
>       run("ZVI Reader", "open="+intput+title)

Watch out for typos, they will wreck your code :)

>       run("Subtract Background...", "rolling=100");
>       run("Invert");
>       setAutoThreshold("Yen");
>       run("Convert to Mask");
>       run("Watershed");
>       run("Set Measurements...", "slice area count mean circularity redirect=None");
>       run("Analyze Particles...", "size=40-120 circularity=0.50-1.00 show=summarize");

This all looks lovely until this line, and this may be why you get no summary table in batch mode.  My Fiji keeps telling me summarize is not a valid choice for show.  I think you want run("Analyze Particles...", "size=40-120 circularity=0.50-1.00 show=Nothing summarize");


>       saveAs("text", output+title+".txt");
>      close();
>     }

>   setBatchMode(true);
>   list = getFileList(input);
>   for (i = 0; i < list.length; i++)
>        doit(input, output, list[i]);
>   setBatchMode(false);
>}

The batch mode bit needs to move up in your code.  Also, not sure why you have the line for setting batch mode back to false.  

Here is my code:

-----------begin----------------

        input = "/path1/";
        list = getFileList(input);                                          
        output = "/path2/";

 setBatchMode(true);              
    for (i=0; i<list.length; i++) {
        path = input+list[i];                                                            
        showProgress(i, list.length);    
        if (!endsWith(path,"/")) open(path);  
if (nImages>=1) {                                          
 
   title=getTitle();                                                                        

run("Subtract Background...", "rolling=100");
       run("Invert");
       setAutoThreshold("Yen");
       run("Convert to Mask");
       run("Watershed");
       run("Set Measurements...", "slice area count mean circularity redirect=None");
       run("Analyze Particles...", "size=40-120 circularity=0.50-1.00 show=Nothing summarize");
       saveAs("text", output+title+".txt");
       close();                                                                                                  
                             
  }
}                                                      

-----------end------------------

I hope this helps you with your troubleshooting.  Good luck!

Best,
Christine

--------------------------------------------
Christine Labno, Ph.D.
Asst. Technical Director
Light Microscopy Core
University of Chicago
Office of Shared Research Facilities
KCBD 1250 900 E. 57th St.
(773) 834-9040 (phone)


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Summarize table not writing in macro

schamber789
Hi Christine,

Thanks very much for your help with this! This will help make my work a lot
easier.

Cheers, Scott


On Mon, Sep 23, 2013 at 10:35 AM, Christine Labno <[hidden email]>wrote:

> Hi Scott,
>
> Since you asked for guidance, here are a couple of suggestions, followed
> by a whole batch process macro based on your code that runs and creates a
> summary table for me on some test images.  Full disclosure, I am being a
> bit lazy and just using a folder full of tif files, so I can't comment on
> any problems with the .zvi file opener.
>
> >On Friday, September 20, 2013 9:04 PM Scott Chamberlain wrote:
> >Subject: Summarize table not writing in macro
>
> >Hello all,
>
> >I have this macro below that works fine on a single image, but doesn't
> work
> >in batch mode. I want to use the macro to process a single folder at a
> time
> >of images with .zvi extension.  I'd appreciate any guidance on where to
> >look for the problem!
>
> >Thanks!
> >Scott Chamberlain
> >Simon Fraser University
>
> >macro "countem [q]" {
> >   title = getTitle;
>
> If you are in batch mode, there won't be a file open at this point, so
> there isn't a way to get a title from it.  Best to move this downstream a
> little.
>
> >   input = "/path1/";
>  >  output = "/path2/";
>
> The way this is written I'm assuming you want to "hard code" in your
> filepaths.  This is a totally valid.  You could also choose to go with
>
>         input = getDirectory("Choose a Directory to PROCESS");
>      list = getFileList(input);
> output = getDirectory("Choose a Directory for SAVING");
>
> to make the macro a little more flexible.  This will direct the user (you)
> to click a folder to process and another to save to each time the macro is
> run.  This way you won't have to modify the code for each run.  It's up to
> you.
>
> >    function doit(input, output, title) {
> >       run("ZVI Reader", "open="+intput+title)
>
> Watch out for typos, they will wreck your code :)
>
> >       run("Subtract Background...", "rolling=100");
> >       run("Invert");
> >       setAutoThreshold("Yen");
> >       run("Convert to Mask");
> >       run("Watershed");
> >       run("Set Measurements...", "slice area count mean circularity
> redirect=None");
> >       run("Analyze Particles...", "size=40-120 circularity=0.50-1.00
> show=summarize");
>
> This all looks lovely until this line, and this may be why you get no
> summary table in batch mode.  My Fiji keeps telling me summarize is not a
> valid choice for show.  I think you want run("Analyze Particles...",
> "size=40-120 circularity=0.50-1.00 show=Nothing summarize");
>
>
> >       saveAs("text", output+title+".txt");
> >      close();
> >     }
>
> >   setBatchMode(true);
> >   list = getFileList(input);
> >   for (i = 0; i < list.length; i++)
> >        doit(input, output, list[i]);
> >   setBatchMode(false);
> >}
>
> The batch mode bit needs to move up in your code.  Also, not sure why you
> have the line for setting batch mode back to false.
>
> Here is my code:
>
> -----------begin----------------
>
>         input = "/path1/";
>         list = getFileList(input);
>         output = "/path2/";
>
>  setBatchMode(true);
>     for (i=0; i<list.length; i++) {
>         path = input+list[i];
>         showProgress(i, list.length);
>         if (!endsWith(path,"/")) open(path);
> if (nImages>=1) {
>
>    title=getTitle();
>
> run("Subtract Background...", "rolling=100");
>        run("Invert");
>        setAutoThreshold("Yen");
>        run("Convert to Mask");
>        run("Watershed");
>        run("Set Measurements...", "slice area count mean circularity
> redirect=None");
>        run("Analyze Particles...", "size=40-120 circularity=0.50-1.00
> show=Nothing summarize");
>        saveAs("text", output+title+".txt");
>        close();
>
>   }
> }
>
> -----------end------------------
>
> I hope this helps you with your troubleshooting.  Good luck!
>
> Best,
> Christine
>
> --------------------------------------------
> Christine Labno, Ph.D.
> Asst. Technical Director
> Light Microscopy Core
> University of Chicago
> Office of Shared Research Facilities
> KCBD 1250 900 E. 57th St.
> (773) 834-9040 (phone)
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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