Login  Register

Re: ImageJ is saving my grayscale AVI files as RED?

Posted by Chris Richie on Sep 14, 2010; 9:01pm
URL: http://imagej.273.s1.nabble.com/ImageJ-is-saving-my-grayscale-AVI-files-as-RED-tp3686921p3686922.html



Thanks for all your comments so far, I have made some progress with my problem.

The movies that I am processing turned out to be RBG-type, they just "look" grayscale because they are brightfield images.

I still require the Bio-formats importer to open them properly in ImageJ because of the (header-related?) bug in the Nikon Elements software.

Right now, "messy/inefficient code" aside, my macro is working to open and process the files I need.
I have very little programming training, just one course in C++ 15 years ago.

My future effort will be to make it more memory and processing time efficient.

Thanks
chris


most recent version:
// batch process to re-header the .AVI files captured by April on the Nikon Elements
// by crichie on 09-10-10.
// Taken from bfOpenAsHyperstack.txt Written by Wayne Rasband
// and another macro from a forum post by Dr K.R. Straatman

requires("1.44");
///
///

dir1 = getDirectory("Choose Source Directory ");
list = getFileList(dir1);
dir2 = dir1+"converted"+File.separator;
File.makeDirectory(dir2);
for (f=0; f<list.length; f++)
        {
       
        if (File.isDirectory(dir1+list[f])){}
        else{
               
                path = dir1+list[f];
                if (endsWith(path, ".db")){}
                else{
                        name = list[f];                        

// begin timestamp_b
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour_b, minute_b, second_b, msec);
// end timestamp_b



// begin name without extension fix


   index = lastIndexOf(name, ".");
   if (index!=-1) name = substring(name, 0, index);

   print("Conversion has started for " +name +".");

// end name without extension fix
                       
                        run("Bio-Formats Macro Extensions");
                        Ext.setId(path);
                        Ext.getCurrentFile(file);
                        Ext.getSizeX(sizeX);
                        Ext.getSizeY(sizeY);
                        Ext.getSizeC(sizeC);
                        Ext.getSizeZ(sizeZ);
                        Ext.getSizeT(sizeT);
                        Ext.getImageCount(n);

                        setBatchMode(true);
                        for (i=0; i<n; i++) {
                          showProgress(i, n);
                          Ext.openImage("plane "+i, i);
                          if (i==0)
                            stack = getImageID;
                          else {
                            run("Copy");
                            close;
                            selectImage(stack);
                            run("Add Slice");
                            run("Paste");
                          }
                        }

                rename(name +"_hs");
                if (nSlices>1) {
                   Stack.setDimensions(sizeC, sizeZ, sizeT);
                   if (sizeC>1) {
                     if (sizeC==3&&sizeC==nSlices) mode = "Composite";
                     else mode = "Color";
                 run("Make Composite", "display="+mode);
                   }
                 }

// setBatchMode(false);

// begin - to reduce the hyperstack to apparently grayscale (but RGB color format).

run("Reduce Dimensionality...", "  frames keep");
run("Grays");
run("RGB Color");

// end - to reduce the hyperstack to apparently grayscale (but RGB color format).

run("AVI... ", "compression=Uncompressed frame=15 save=" +dir2 +"\\" +name +".avi");
print (name +" has been converted to 15fps and saved.");

rename(name+".avi");

selectWindow(name +"_hs");
close(); // this does not need to be open anymore

// begin to split movies

if (sizeT <= 4500) {
                   print(name +" is less than or equal to 5 minutes and will not be split.");

         }
   else {
         print("The file is greater than 5 minutes and will be split.");
         print("This macro is currently set to discard frames after 10 minutes.");

         selectWindow(name +".avi");
         run("Duplicate...", "title=" +name +"-1.avi duplicate range=1-4500");
         run("AVI... ", "compression=Uncompressed frame=15 save=" +dir2 +"\\" +name +"-1.avi");

         selectWindow(name +".avi");
         run("Duplicate...", "title=" +name +"-2.avi duplicate range=4501-9000");
         run("AVI... ", "compression=Uncompressed frame=15 save=" +dir2 +"\\" +name +"-2.avi");

/// remove these remarks to gain another 5 minutes of data (minutes 11 - 15).
// selectWindow(name +".avi");
// run("Duplicate...", "title=" +name +"-3.avi duplicate range=9001-13500");
// run("AVI... ", "compression=Uncompressed frame=15 save=" +dir2 +"\\" +name +"-3.avi");


         print("Chunking for " +name +" is complete.");
         }
// end to split movies.

                   getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour_e, minute_e, second_e, msec);
                   elapsed = ((minute_e - minute_b)*60)  + (second_e - second_b);
                   print("Time elapsed = " +elapsed +" sec.");
                   print("");  // an empty space line.

}


//setBatchMode(false);  //remmed out to get the upstream files visible

// Ext.close();  //remming this out to see if verbose error list goes away.

// setBatchMode(false);
                                }
                        }
///
///