Posted by
Matthew Jacobs on
May 19, 2014; 11:15pm
URL: http://imagej.273.s1.nabble.com/Recursive-processing-of-a-directory-not-working-correctly-tp5007797.html
I've been combing this forum looking at other examples of code similar to mine but I still have not been able to solve the issue.
I am processing images in Fiji/imageJ using a macro code. The code is meant to recursively search a given directory for image files (in this case .vsi files) and convert them to .tiff using the built in bioformats functions.
I have cobbled the following code together from several examples (I am not a programmer, I have a biology degree), and I am returning an error that the specified file does not exist. Printout and debug console show the error occurs on the
run("Bio-Formats... line of the macro.
For reference:
All of my images have the following general directory structure:
~/Brain_01/Slice_01/Slice_01_01.vsi
An actual example is as follows for the second image in this set:
~/K259_tlx3cre/K259_1of3_02/K259_1of3_01_02.vsi
I really, really appreciate all the help you guys provide! I am completely stuck right now and am just banging my head against the keyboard at this point. Also, I think I've followed all the rules for posting. If not please just point out the error of my ways.
Finally here is the macro code I have written so far is attached as a text file which formats well in notepad++, and I will also paste the code here but have no idea how it will format once the post goes up.
Dialog.create("File type");
Dialog.addString("File suffix: ", ".vsi", 5);
Dialog.show();
suffix = Dialog.getString();
inDir = getDirectory("Choose Directory Containing " + suffix + " Files ");
outDir = getDirectory("Choose Directory for TIFF Output ");
setBatchMode(true);
processFiles(inDir, outDir, "");
print("Done!");
function processFiles(inBase, outBase, sub) {
flattenFolders = true; // this flag controls output directory structure
print("Processing folder: " + sub);
list = getFileList(inBase + sub);
if (!flattenFolders) File.makeDirectory(outBase + sub);
for (i=0; i<list.length; i++) {
path = sub + list[i];
//upath = toUpperCase(path); only need if the file extension is case sensitive
upath = path; //avoids the previous line
if (endsWith(path, "/")) {
processFiles(inBase, outBase, path);
}
else if (endsWith(upath, suffix)) {
print("Importing " + suffix + " = " + list[i]);
run("Bio-Formats Windowless Importer", "open=inBase + path color_mode=Default view=Hyperstack stack_order=XYCZT");
print("Blue...");
selectImage(1);
title1 = getTitle();
run("Blue");
print("Green...");
selectImage(2);
title2 = getTitle();
run("Green");
print("Red...");
selectImage(3);
title3 = getTitle();
run("Red");
print("Merging Channels...");
run("Merge Channels...", "red=&title3 green=&title2 blue=&title1 gray=*None* cyan=*None* magenta=*None* yellow=*None* create keep");
print("Converting to RGB");
run("RGB Color");
saveAs("Tiff", outbase + path);
run("Close All");
}
}
}
Matthew Jacobs,
Research Assistant
Callaway Neuroscience Laboratory
The Salk Institute for Biological Studies