Problem with batch processing

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

Problem with batch processing

sam
Hi there,

I am trying to write a macro to do some basic batch processing on all open images.  For some reason it only does 2 or 3 of the open images, then stops, so I have to keep running the macro until the job is done.

Can anyone see what I am doing wrong? Thanks for your help!

The macro is below:

dir = getDirectory("Choose a Directory");

for (i=1; i<=nImages; i++) {
   selectImage(i);
   processImage();  
}

function processImage() {
   
        title=getTitle;
        run("Make Composite", "display=Color");
        Stack.setChannel(1);
        resetMinAndMax();
        run("Red");
        Stack.setChannel(2);
        resetMinAndMax();
        run("Grays");
        Stack.setChannel(3);
        resetMinAndMax();
        run("Green");

      saveAs("tiff", dir+title);
        close;

}

Reply | Threaded
Open this post in threaded view
|

Re: Problem with batch processing

Jerome Mutterer-3
Dear Samuel
Your problem is that you are selecting images with select image(i) and then
closing the processed image. When you do this the list of images changes:
image 1 goes away and image 2 becomes image 1, so it is skipped when you
selectImage(2).
What you can do is selectImage(nImages) so that you always work with the
last image from the images list.
Sincerely
Jerome.
Le 5 avr. 2014 10:20, "sam" <[hidden email]> a écrit :

> Hi there,
>
> I am trying to write a macro to do some basic batch processing on all open
> images.  For some reason it only does 2 or 3 of the open images, then
> stops,
> so I have to keep running the macro until the job is done.
>
> Can anyone see what I am doing wrong? Thanks for your help!
>
> The macro is below:
>
> dir = getDirectory("Choose a Directory");
>
> for (i=1; i<=nImages; i++) {
>    selectImage(i);
>    processImage();
> }
>
> function processImage() {
>
>         title=getTitle;
>         run("Make Composite", "display=Color");
>         Stack.setChannel(1);
>         resetMinAndMax();
>         run("Red");
>         Stack.setChannel(2);
>         resetMinAndMax();
>         run("Grays");
>         Stack.setChannel(3);
>         resetMinAndMax();
>         run("Green");
>
>       saveAs("tiff", dir+title);
>         close;
>
> }
>
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Problem-with-batch-processing-tp5007213.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
Reply | Threaded
Open this post in threaded view
|

Re: Problem with batch processing

dscho
In reply to this post by sam
Hi Sam,

On Sat, 5 Apr 2014, sam wrote:

> dir = getDirectory("Choose a Directory");
>
> for (i=1; i<=nImages; i++) {

nImages is the number of currently open images, not the number of files in
the directory you just chose.

A better method would be to use
http://imagej.nih.gov/ij/docs/guide/146-29.html#sub:Batch with the part of
the macro that actually works on a single image (skipping the part that
saves the image because the Batch command already does that).

Ciao,
Johannes

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