|
Hi,
I've adapted the batch folder process macro to perform background subtraction on all images in a folder but, being something of an amateur at this game, I'm having problems getting it to work.
// This macro subtracts a background image from each TIFF in a folder
requires("1.33s");
sdir = getDirectory("select source directory");
final = "final"+File.separator;
ddir = sdir+final;
File.makeDirectory(ddir);
background = File.openDialog("select background image for subtraction");
open(background);
background = getImageID();
setBatchMode(true);
count = 0;
countFiles(sdir);
n = 0;
processFiles(sdir);
//print(count+" files processed");
function countFiles(sdir) {
list = getFileList(sdir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
countFiles(""+sdir+list[i]);
else
count++;
}
}
function processFiles(sdir) {
list = getFileList(sdir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
processFiles(""+sdir+list[i]);
else {
showProgress(n++, count);
path = sdir+list[i];
processFile(path);
}
}
}
function processFile(path) {
if (endsWith(path, ".tif")) {
open(path);
target = getImageID();
imageCalculator("Difference create", target, background);
result = getImageID();
selectImage(target);
close();
selectImage(result);
saveAs("tiff", ddir+list[i]);
close();
}
}
The macro seems to conduct the subtraction and saves all the image files to the new folder "\final" but then overwrites them with the original images and I can't work out why!
Help plz?
Thanks,
Chris
|