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"); |
On Sunday 21 September 2008, Paul Grimm wrote:
> 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 Hi, What is the error that you get? G |
Sorry, I should have stated that.
When I run the macro after installing it into the plugins menu or from an open text window the entire macro processes correctly. When I run it from a keyboard shortcut or after installing it into the macros menu the images are processed, the results go to the results window, but the file is not saved to the hard drive. The last instructions are simply ignored by the macro which seems to just close. No error messages appear. -- Paul C. Grimm "The first rule is to keep an untroubled spirit. The second is to look things in the face and know them for what they are." Marcus Aurelius, Roman Emperor On Sep 21, 2008, at 1:00 AM, Gabriel Landini wrote: > On Sunday 21 September 2008, Paul Grimm wrote: >> 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 > > Hi, > What is the error that you get? > > G |
On Sep 22, 2008, at 10:48 AM, Paul Grimm wrote:
> Sorry, I should have stated that. > When I run the macro after installing it into the plugins menu or > from an open text window the entire macro processes correctly. > When I run it from a keyboard shortcut or after installing it into > the macros menu the images are processed, the results go to the > results window, but the file is not saved to the hard drive. The > last instructions are simply ignored by the macro which seems to > just close. No error messages appear. > >> Hi Paul, I don't think you are providing sufficient information. Can you create a very simple macro that shows the errant behavior and post that to this list? Cheers, Ben |
In reply to this post by Paul Grimm-2
That fixed it!!!!
Thank you so much. Paul -- On Sep 22, 2008, at 9:08 AM, Wayne Rasband wrote: > > Your macro may be failing because a "}" is in the wrong place. I > suspect that the "}" just before > > savepath = "/Users/Paul/Desktop/macroresults/" + "512PixWhite > analysis" + ".xls"; > > should instead be added the end of the macro. > > Sincerely, > > -wayne |
Could you please take me from the list.
Thanks a lot! Florian Blaschke E-mail: [hidden email] ________________________________ From: ImageJ Interest Group on behalf of Paul Grimm Sent: Tue 9/23/2008 5:18 AM To: [hidden email] Subject: Re: Problem calling an Installed Macro That fixed it!!!! Thank you so much. Paul -- On Sep 22, 2008, at 9:08 AM, Wayne Rasband wrote: > > Your macro may be failing because a "}" is in the wrong place. I > suspect that the "}" just before > > savepath = "/Users/Paul/Desktop/macroresults/" + "512PixWhite > analysis" + ".xls"; > > should instead be added the end of the macro. > > Sincerely, > > -wayne |
Free forum by Nabble | Edit this page |