Problems using Save XY-Coordinates... in a batch macro
Posted by MtnMan on Oct 15, 2009; 6:31pm
URL: http://imagej.273.s1.nabble.com/Problems-using-Save-XY-Coordinates-in-a-batch-macro-tp3690736.html
Hi all,
I have 8-bit .tif images that I would like to export to a .txt file using "Save XY Coordinates." When running the function on a single image there is a pup-up that allows me to specify the background intensity. When a background value is selected the function does not include pixels that are more intense in the txt output. For my further analysis I want all of the pixel values exported regardless of their value. Save XY Coordinates, by default, uses the top left pixel as the background value. After choosing the background value, a second window allows me to choose the save as location and file name.
What I want to do is run Save XY Coordinates as a batch process where I choose a folder, and all of the images in that folder are converted to .txt files. I also want the background value to be set at 256 or higher, I want the save as name to be the same as the .tif. If I can set a second "output" folder that would optimal, but not necessary.
I have pasted the macro script I have am using below. I searched the web to find the shell script and simply added the Save XY Coordinates function where appropriate. When I run this macro I am able to choose a directory, and the first image is processed, then I get the save as dialog (with the proper .txt file name in the save as field). If I click save, then the .txt file is saved, but it does not use the background value I supplied in the macro. Instead it uses the default top left pixel value. If I can get it to use the correct background value I can live with having to click OK for every iteration, but if anyone has any suggestions on how to fix both problems that would be great!
As a caveat I have experience writing in the R language, but very little experience in this macro language. I can generally understand what example code is supposed to do, but I don't really understand the syntax too well.
Thanks for taking a look.
Duane
// "BatchProcessFolders"
//
// This macro batch processes all the files in a folder and any
// subfolders in that folder. In this example, it runs the Subtract
// Background command of TIFF files. For other kinds of processing,
// edit the processFile() function at the end of this macro.
requires("1.33s");
dir = getDirectory("Choose a Directory ");
setBatchMode(true);
count = 0;
countFiles(dir);
n = 0;
processFiles(dir);
print(count+" files processed");
function countFiles(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
countFiles(""+dir+list[i]);
else
count++;
}
}
function processFiles(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
processFiles(""+dir+list[i]);
else {
showProgress(n++, count);
path = dir+list[i];
processFile(path);
}
}
}
function processFile(path) {
if (endsWith(path, ".tif")) {
open(path);
txtname = substring(path, 0, lengthOf(path)-4) + ".txt";
run("Save XY Coordinates...", "background = 300 save = ["+txtname+"]");
close();
}
}