Calling an ImageJ macro on files in sets of 3
Posted by syntonicC on
URL: http://imagej.273.s1.nabble.com/Calling-an-ImageJ-macro-on-files-in-sets-of-3-tp5013674.html
I have a bunch of image files in one folder (TIF). I already wrote a macro to split the files into RGB channels and then save them to the same directory. The output is thus something like this:
-File 1
-File 1 (red)
-File 1 (green)
-File 1 (blue)
-File 2
-File 2 (red) ...
etc.
Next I am using the JACoP plugin which takes two image files and computes various kinds of correlation coefficients/analysis between the inputs. For each directory, I want to do the following:
Loop through the following for each file in my directory:
1. Set input file one to File X (red) and file two to File X (blue)
2. Click Analyze
3. Set input file one to File X (red) and file two to File X (green)
4. Click Analyze
5. Set input file one to File x (blue) and file two to File x (green)
6. Click Analyze
Then finally:
7. Save the analysis output log
The problem is that I don't know how to tell ImageJ how to call each of the color files in that order. How do I specify that it pulls out the files in chunks of three (RGB for image 1), analyses them, and then moves on to the next chunk of three (RGB for image 2)?
My approach originally was something like this:
dir=getDirectory("Choose a Directory");
print(dir);
list = getFileList(dir);
for (i=0; i<list.length; i++) {
open(list[i]);
selectImage(i+1);
blue = getTitle();
selectImage(i+2);
green = getTitle();
selectImage(i+3);
red = getTitle();
//Analyze the red, green, and blue images with JACoP plugin
//Move to next set of three images and repeat in next loop through
}
But this will obviously not work on the second iteration of the loop because it will need to be i+4, i+5, i+6 etc. There is probably an ImageJ function or basic approach to doing this kind of batch analysis but I'm not sure what to look for. Any suggestions/pseudocode to point me in the right direction are appreciated!