Macro for merging 2 channels of .nd2 files

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Macro for merging 2 channels of .nd2 files


I'm trying to write a macro where .nd2 images/file within a folder are
opened, split into 2 channels, and merged into a single image and saved as a
new merged file.

When I use Bio-Format Importer to split the channels, it generates 2
images/channels named:
"file_name" - C=0
"file_name" - C=1

Here's my macro code so far:

path = getDirectory('Choose Directory');
filelist = getFileList(path);
output = path+"MergedJPG"+File.separator;

for (i=0; i< filelist.length; i++) {
if (endsWith(filelist[i], ".nd2")) {

name = path + filelist[i];
run("Bio-Formats Importer", "open= ["+name+"] color_mode=Default
view=Hyperstack stack_order=XYCZT color_mode=Default split_channels");
        red = filelist[i]+" - C=1";
        green = filelist[i]+" - C=0";
run("Merge Channels...", "c1=["+red+"] c2=["+green+"] create");
saveAs("jpeg", output + filelist[i]);

It's almost there. When I run it,  I choose the directory (in this case the
folder "nd2" containing my .nd2 image files), it creates the MergedJPG
folder fine, but then this window pops up and I still have to click on each
.nd2 file with in my chosen folder, and in the right order, for each image
to get processed and saved as the merged .jpg files.
I assume I'm just missing some simple thing in order for it to actually
automate and batch process all the .nd2 files in my chosen folder without me
having to select/click on each one.

Thanks for the help,

Sent from:

ImageJ mailing list: