Can getDirectory() automatically select a predefined folder path?
Posted by DaveMc on Sep 05, 2014; 8:09pm
URL: http://imagej.273.s1.nabble.com/Can-getDirectory-automatically-select-a-predefined-folder-path-tp5009535.html
Hi All,
I'm writing a macro for a user of our core facility and wondering if I can streamline it even more. What he wants to do is open large folders of ~1500 RGB images, split the channels saving only the red and green appending the file names in a new subfolder, then convert and save those as 16-bit in another new subfolder.
The macro is working well but he has to wait until the split step is done then choose that folder to start the 16-bit step.
The question is...can I use the getDirectory function, or another option, to get the macro to automatically select the subfolder the split channels are in by path and automatically start the 16-bit step without him having to choose it?
Thanks!
Dave
Here's the code...
------------------
macro "Split channels then convert to 16-bit"
{
{
// Open and split channels then save to new folder...
dir1 = getDirectory("Choose Original Images Directory");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
path = dir1+list[i];
open(path);
run("Split Channels");
dir2 = dir1+"split"+File.separator;
File.makeDirectory(dir2);
path = dir2+list[i];
dotIndex = lastIndexOf(path, "."); path = substring(path, 0, dotIndex); // remove ext.
// save(path+"_blue.tif");
close();
save(path+"_green.tif");
close();
save(path+"_red.tif");
close();
}
}
{
// Open split channels and save as 16-bit to new folder...
dir1 = getDirectory("Choose Split Channels Directory");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
path = dir1+list[i];
open(path);
run("16-bit");
dir2 = dir1+"16-bit"+File.separator;
File.makeDirectory(dir2);
path = dir2+list[i];
dotIndex = lastIndexOf(path, "."); path = substring(path, 0, dotIndex); // remove ext
save(path+"-16bit.tif");
close();
}
}
{
exit("Finished")
}
}