Reputation: 11
I am writing my first ImageJ macro script. Right now, I have a working script that opens a file in one directory, removes the first 24 slices from the file, and then saves the file as a tif in a different directory. The problem is that my files are stacks and as each file opens I am given a prompt for Bio-Formats Import Options. I would like to code in the options into my macro so that I don't have to manually OK the options each time. Could someone provide me some guidance?
dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
open(dir1+list[i]);
// INSERT MACRO HERE
run("Slice Remover", "first=1 last=24 increment=1");
saveAs("TIFF", dir2+list[i]);
close();
}
Upvotes: 1
Views: 1837
Reputation: 352
Replace the line
open(dir1+list[i]);
with
s = "open=["+dir1+list[i]+"] autoscale color_mode=Grayscale rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT";
run("Bio-Formats Importer", s);
The exact formatting of the string s
depends on what settings you require for the Bio-Formats importer. If you do Plugins > Macros > Record
and then open one of your images, you can "record" the formatting of the string to use in your macro.
An alternative approach is to tell the importer to just open the files without using the dialog. This can be achieved by checking the windowless option for the file type you are using in Bio-Formats Plugins Configuration. However, this is not a robust solution because it wouldn't (necessarily) work for others running your code.
Upvotes: 1