Z-stack max intensity macro

Hi everyone,
I would like to write a macro that does max intensity projection of z-stacks of a whole batch of images and saves the resulting images in a .tiff-format.
My raw data images are in a .nd-format and contain 3 different colors/channels.
The idea behind the macro I have written so far is as following:

  1. check if the image file in my input folder ends with “.nd” since I only want to process those files
  2. run Bio-Formats importer in order to import the .nd-file as a colorized hyperstack
  3. run z max intensity projection
  4. save the resulting image as a tiff-file
    –>this should be done for all .nd-files in my input folder, that’s why I wrote the for loop.

my macro:

input = getDirectory("Choose a Directory"); 
list = getFileList(input); 
output = input + "Max Projections" + File.separator;
if (File.exists(output)) 
   exit("Destination directory already exists; remove it and then run this macro again"); 
for (i=0; i<list.length; i++) { 
        if(endsWith(list[i], ".nd")) {
        		run("Bio-Formats Importer", "open=["+ input + list[i] +"] autoscale color_mode=Colorized rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
                run("Z Project...", "projection=[Max Intensity]"); 
                saveAs("tiff", output + getTitle); 

The problem I have at the moment is that it only seems to process one of the files/images in my folder (always the same one). And this file is not even a .nd-file but a .stk-file…?!

Any ideas/suggestions how to solve this problem would be very much appreciated!

Thank you very much :slight_smile:

Looking at my version of similar code, I had a file separator between the input folder and the file name.

I see that you included that with your output folder, but not the input folder.

You might try some print statements to see what you are processing, and not run things in batch mode to start so that you can watch what is happening.

Hi @nbara, do you have a list of the files in the directory? When you open a MetaMorph nd file with Bio-Formats it will try and locate the related stk or tiff files in the same directory, so it may be correct that it is processing the stk file. If you try to open the file manually using the Bio-Formats Importer do you see the same issues or does it behave differently?

Hey @dgault and @Research_Associate
Thanks for your inputs.
I could “fix” the problem. It seems that Bio-Formats cannot properly handle metamorph data such as nd files. This is a known issue and has been reported to the developers several times already.
In the meantime, as a work-around, I realized that getting rid of underscores in my nd as well as stk files kind of solves the problem and I could manage to get my script running.
Please see also imagej/imagej - Gitter