How to reference next image in Batch Macro

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to reference next image in Batch Macro

Anish Prasanna
Hi all,
I am working on a project that requires me to do image subtraction on consecutive images in a folder. I wanted to automate this task. However, I am not totally sure as to how to access the next image in the folder and subtract it from the current image in process through the batch macro.
Reply | Threaded
Open this post in threaded view
|

Re: How to reference next image in Batch Macro

G. Esteban Fernandez
This will prompt you for a directory and get you a list of all files in
that directory, stored in an array called 'files' (or whatever arbitrary
name you choose):

dir = getDirectory();
files = getFileList(dir);

You can then refer to consecutive files using consecutive numbers in the
array index, e.g.: files[0] and files[1].
Use a for loop to go through the entire list:

for(i = 0; i < files.length - 1; i++){
     open(dir + files[i]);
     open(dir + files[i+1]);
}

-Esteban
On Aug 7, 2015 10:29 AM, "Anish Prasanna" <[hidden email]> wrote:

> Hi all,
> I am working on a project that requires me to do image subtraction on
> consecutive images in a folder. I wanted to automate this task. However, I
> am not totally sure as to how to access the next image in the folder and
> subtract it from the current image in process through the batch macro.
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/How-to-reference-next-image-in-Batch-Macro-tp5013954.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: How to reference next image in Batch Macro

Anish Prasanna
This post has NOT been accepted by the mailing list yet.
I tried doing this, but I got an error that said "number or numeric function expected in line 1. i=0; dir = getDirectory(<)>;"

Any idea as to what may be wrong?


Thanks,
Anish Prasanna
Reply | Threaded
Open this post in threaded view
|

Re: How to reference next image in Batch Macro

Anish Prasanna
here is the current code i have:

dir = getDirectory("DSC_0179.JPG");
files = getFileList(dir);
i=0;
for(i = 0; i < files.length - 1; i++){
     open(dir + files[i]);
     open(dir + files[i+1]);
     imageCalculator("Subtract create",(dir + files[i+1]),(dir + files[i]));
}
Reply | Threaded
Open this post in threaded view
|

Re: How to reference next image in Batch Macro

G. Esteban Fernandez
This is what I'd do:

dir = getDirectory("Choose a folder");
files = getFileList(dir);

for(i = 0; i < files.length - 1; i++){
     open(dir + files[i]);
     image1 = getTitle();

     open(dir + files[i+1]);
     image2 = getTitle();

     imageCalculator("Subtract create", image2, image1);

     selectWindow(image1);
     close();
     selectWindow(image2);
     close();
}

At the end you're left with all the subtraction results open in separate
windows.

-Esteban
On Aug 13, 2015 11:25 AM, "Anish Prasanna" <[hidden email]> wrote:

> here is the current code i have:
>
> dir = getDirectory("DSC_0179.JPG");
> files = getFileList(dir);
> i=0;
> for(i = 0; i < files.length - 1; i++){
>      open(dir + files[i]);
>      open(dir + files[i+1]);
>      imageCalculator("Subtract create",(dir + files[i+1]),(dir +
> files[i]));
> }
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/How-to-reference-next-image-in-Batch-Macro-tp5013954p5014010.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