Login  Register

Error in directory processing and saving results

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Error in directory processing and saving results

aaron
1 post
Hello,

I seem to be having a problem with a macro I am trying to write which will process my nikon elements captured z-stack images (.nd2). The macro is meant to open TIF files (which were previously generated from  the .nd2 files) from a selected directory, split and save the channels to a new directory, merge them back together, then stitch the z-stacks and save the resulting projection as an .avi file in another new directory.

The macro runs fine with under 10 files in the input directory, but somewhere between 10 and 20 files, something happens and the macro fails to write the .avi files. All other operations proceed as scripted (opening, splitting and saving etc). I have written a similar script for single plane TIF files which this macro was based on (and which is also capable of processing much more than 10 files).

The macro is as follows:

path = getDirectory("Choose a Directory");
filename = getFileList(path);

newDir=path + "Split" + File.separator;
File.makeDirectory(newDir);

newDir2=path + "AVI" + File.separator;
File.makeDirectory(newDir2);

for (i=0; i<filename.length; i++) {
        if(endsWith(filename[i], ".tif")) {
                open(path+filename[i]);
                red=File.nameWithoutExtension+"_red";
                blue=File.nameWithoutExtension+"_blue";
                Name=getTitle();

                run("Split Channels");

               
                selectWindow("C1-"+filename[i]);
                run("RGB Color");
                saveAs("Tiff",newDir+File.nameWithoutExtension+"_blue");

                selectWindow("C2-"+filename[i]);
                run("RGB Color");
                saveAs("Tiff",newDir+File.nameWithoutExtension+"_red");

                run("Merge Channels...", "c1=["+red+".tif] c3=["+blue+".tif] create");

                selectWindow("RGB");
                run("3D Project...", "projection=[Brightest Point] axis=Y-Axis slice=0.10 initial=0 total=360 rotation=10 lower=1 upper=255 opacity=0 surface=100 interior=50

interpolate");
                selectWindow("RGB");
                close("RGB");
               
                selectWindow("Projection of  RGB");
                run("AVI... ", "compression=JPEG frame=8 save="+newDir2+"\\"+filename[i]+".avi");
                close();
        }
}


I have also tried calling:
setBatchMode(true); at the start of the macro (to avoid macro 'confusion' at opening and closing so many windows) and
call("java.lang.System.gc"); at the end (as I thought it could be a memory issue), though these made no difference to the outcome.

Any assistance here would be greatly appreciated. Please also forgive me regarding the state of the macro (its a little obvious but I'm very new to this).

Regards,
Aaron