Re: Batch processing and saving multiple result files to a single directory

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

Re: Batch processing and saving multiple result files to a single directory

Rasband, Wayne (NIH/NIMH) [E]
On Dec 31, 2012, at 5:38 PM, greg2308 wrote:

> Hello everyone,
>
> I am new to ImageJ macro language. By using the ‘macro recorder’ and
> searching the forums I have created a macro that does everything I need to a
> single image. I need help with two things. 1) using the macro to process all
> images in a single directory (perhaps by using batch processing), and 2)
> saving the results from each image to a separate spreadsheet, ideally
> located in the same directory. For example, in a directory of 20 images, I
> would like 20 different result files.

Here is an expanded version of your macro that does this:

  dir = getDirectory("Choose a directory");
  list = getFileList(dir);
  setBatchMode(true);
  for (i=0; i<list.length; i++) {
     if (endsWith(list[i],".xls"))
        exit("Directory must contain only images");
     open(dir+list[i]);
     run("Select All");
     run("Plot Profile");
     Plot.getValues(x, y);
     close;  //plot
     close;  //image
     run("Clear Results");
     for (j=0; j<x.length; j++) {
        setResult("x", j, x[j]);
        setResult("y", j, y[j]);
     }
     setOption("ShowRowNumbers", false);
     updateResults;
     path = dir+"results"+IJ.pad(i,3)+".xls";
     saveAs("results", path);
  }

> Here is the macro:
>
> run("Select All");
> run("Plot Profile");
>  Plot.getValues(x, y);
>  run("Clear Results");
>  for (i=0; i<x.length; i++) {
>     setResult("x", i, x[i]);
>     setResult("y", i, y[i]);
>  }
>  setOption("ShowRowNumbers", false);
>  updateResults;
>
> Any help will be very much appreciated.
>
> Thanks!
>
> --
> View this message in context: http://imagej.1557.n6.nabble.com/Batch-processing-and-saving-multiple-result-files-to-a-single-directory-tp5001293.html
> Sent from the ImageJ mailing list archive at Nabble.com.

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

Re: Batch processing and saving multiple result files to a single directory

Alistair MacDougall
Following on from Wayne's reply, you might like to use a couple of alternative lines to give you the same name for the saved file as for the image.

In place of;
path = dir + "results" + IJ.pad(i,3) + ".xls";

you can put:
n = lastIndexOf(list[i], ".");
imagename = substring(list[i], 0, n);
path =dir + imagename + ".xls";

Best Wishes, Alistair


-------------------------------------------

On Dec 31, 2012, at 5:38 PM, greg2308 wrote:

> Hello everyone,
>
> I am new to ImageJ macro language. By using the ‘macro recorder’ and
> searching the forums I have created a macro that does everything I need to a
> single image. I need help with two things. 1) using the macro to process all
> images in a single directory (perhaps by using batch processing), and 2)
> saving the results from each image to a separate spreadsheet, ideally
> located in the same directory. For example, in a directory of 20 images, I
> would like 20 different result files.

Here is an expanded version of your macro that does this:

  dir = getDirectory("Choose a directory");
  list = getFileList(dir);
  setBatchMode(true);
  for (i=0; i<list.length; i++) {
     if (endsWith(list[i],".xls"))
        exit("Directory must contain only images");
     open(dir+list[i]);
     run("Select All");
     run("Plot Profile");
     Plot.getValues(x, y);
     close;  //plot
     close;  //image
     run("Clear Results");
     for (j=0; j<x.length; j++) {
        setResult("x", j, x[j]);
        setResult("y", j, y[j]);
     }
     setOption("ShowRowNumbers", false);
     updateResults;
     path = dir+"results"+IJ.pad(i,3)+".xls";
     saveAs("results", path);
  }

> Here is the macro:
>
> run("Select All");
> run("Plot Profile");
>  Plot.getValues(x, y);
>  run("Clear Results");
>  for (i=0; i<x.length; i++) {
>     setResult("x", i, x[i]);
>     setResult("y", i, y[i]);
>  }
>  setOption("ShowRowNumbers", false);
>  updateResults;
>
> Any help will be very much appreciated.
>
> Thanks!

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