Login  Register

Problem calling an Installed Macro

Posted by Paul Grimm-2 on Sep 21, 2008; 5:14am
URL: http://imagej.273.s1.nabble.com/Problem-calling-an-Installed-Macro-tp3695003.html

I hope the smart people on this forum can help me. I have been  
lurking on this site for a few years and using ImageJ and before  
that, NIH Image for a decade.

I have a problem with calling a macro.
I have a pretty complicated image processing macro for processing a  
folder full of images and using the setbatchmode function.

when I call the macro directly from an open text window (Macros-Run  
Macro or Apple-R) it runs perfectly, even on a folder full of images.
When I call the identical macro after loading it into the macros menu  
(Plugins->Macros->Install-> MyMacro, then going directly to it in the  
menu (Plugins->Macros-> MyMacro) or  accessing a keyboard shortcut  
(lowercase), it fails.

It starts and processes the images fine, but it fails during the  
saving portion at the end
somewhere around here

...
selectWindow("tempTotalImage.tif");
close();
close();
close();


call("java.lang.System.gc");
         }
     }
  call("java.lang.System.gc");
}

savepath = "/Users/Paul/Desktop/macroresults/" + "512PixWhite  
analysis" + ".xls";
saveAs("Measurements", savepath);
print(savepath);
run("Clear Results");
call("java.lang.System.gc");

...
Any suggestions why that might be happening?

I will attach the whole macro after my signature.
I am using the latest Image J build (1.41M) on a MacBook, the memory  
monitor shows lots of free memory..

Thanks so much.
--




--


Paul C. Grimm
Professor of Pediatrics
Dept of Pediatric Nephrology
Lucile Packard Children's Hospital
Stanford University School of Medicine
G306, MC 5208
300 Pasteur Drive
Stanford, CA 94305-5208
USA

phone   650-723-7903
fax       650-498-6714



"Obstacles are those frightful things you see when you take your eyes  
off your goal"
Henry Ford

------------

THE WHOLE MACRO
macro "Tissue area for GN8 Polarized [b]" {
     requires("1.34n");
        title = "untitled";
     dir = getDirectory("Choose a Directory ");
     list = getFileList(dir);
     start = getTime();
//run("Set Measurements...", "area display redirect=None decimal=3");

     //for (i=0; i<1; i++) {
     for (i=0; i<list.length; i++) {
         path = dir+list[i];
         showProgress(i, list.length);
         if (!endsWith(path,"/")) open(path);
         if (nImages>=1) {



   run("Options...", "iterations=1 count=1");
run("Colors...", "foreground=black background=white selection=yellow");
//this next line gets the name of the image, and is used later to  
label the result in the table
        title =getTitle();
  run("Size...", "width=512 height=512 constrain interpolate");
     setLocation(515, 100);
setBatchMode(true); // runs up to 6 times faster

selectWindow(title);
run("Duplicate...", "title=title2");
run("Duplicate...", "title=matrixtemp");
selectWindow("title2");


// here is the total tissue part
   run("Options...", "iterations=1 count=1");
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
run("Duplicate...", "title=Hue2");


selectWindow("Hue");
   setThreshold(0, 57);
run("Convert to Mask");


selectWindow("Hue2");
   setThreshold(203, 255);
run("Convert to Mask");


selectWindow("Saturation");
   setThreshold(20, 255);
run("Convert to Mask");


selectWindow("Brightness");
close();


imageCalculator("OR create", "Hue","Hue2");
//run("Make Binary", "thresholded remaining black");
//selectWindow("Result of Hue");
     setLocation(0, 200);

imageCalculator("AND create", "Saturation","Result of Hue");
//run("Make Binary", "thresholded remaining black");
//selectWindow("Result of Saturation");
//now we do a dilation to fill in the spaces then do an analyze  
particles to fill in the holes
run("Dilate");
run("Dilate");
run("Analyze Particles...", "size=50-Infinity circularity=0.00-1.00  
show=Masks include");


rename("TotalTissue");
// was tubuli

selectWindow("Saturation");
close();
selectWindow("Result of Hue");
close();
selectWindow("Hue");
close();
selectWindow("Hue2");
close();


//next we add the Matrix part

selectWindow("matrixtemp");
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
setThreshold(200, 255);
run("Convert to Mask");

selectWindow("Saturation");
   setThreshold(63, 255);
run("Convert to Mask");

selectWindow("Brightness");
  close();


imageCalculator("AND create", "Hue","Saturation");

selectWindow("Result of Hue");
rename("Matrix");

//run("Make Binary", "thresholded remaining black");
selectWindow("Saturation");
close();

selectWindow("Hue");
close();



//this next line renames the TotalTissue result window so the result  
is copied to the table with a name
selectWindow("TotalTissue");
rename("White Total - " +title);
setThreshold(250, 255);

run("Make Binary", "thresholded remaining black");
run("Set Measurements...", "area limit display redirect=None  
decimal=1");
run("Measure");

//here we save the image to the hard drive so we can get to it after  
the batchmode is turned off
saveAs("Tiff", "/Users/Paul/Desktop/macroresults/tempTotalImage.tif");

//this next line renames the Matrix result window so the result is  
copied to the table with a name
selectWindow("Matrix");
rename("White Matrix - " +title);
setThreshold(250, 255);
     setBatchMode(false);
run("Make Binary", "thresholded remaining black");
run("Set Measurements...", "area limit display redirect=None  
decimal=1");
run("Measure");
setLocation(1030, 100);
open("/Users/Paul/Desktop/macroresults/tempTotalImage.tif");
setLocation(0, 100);

wait(2000);
selectWindow("tempTotalImage.tif");
close();
close();
close();


call("java.lang.System.gc");
         }
     }
  call("java.lang.System.gc");
}

savepath = "/Users/Paul/Desktop/macroresults/" + "512PixWhite  
analysis" + ".xls";
saveAs("Measurements", savepath);
print(savepath);
run("Clear Results");
call("java.lang.System.gc");