Hi there,
I am using ImageJ for a while but only now diving deeper in IJM macro language. My Problem: I want to save the "Summary" file output from my macro to a text file. The macro works but no text file is generated. I tried several variations, but nothing worked. Here is my macro: run("Close All"); path = File.openDialog("Choose a File"); open(path) macro "DAPI cell count - 20X" { run("Unsharp Mask...", "radius=1 mask=0.60"); run("Subtract Background...", "rolling=50"); run("8-bit"); setAutoThreshold("Triangle dark"); //run("Threshold..."); //setThreshold(50, 255); setOption("BlackBackground", false); run("Convert to Mask"); run("Watershed"); run("Analyze Particles...", "size=100-Infinity display clear summarize add"); close(); path = File.openDialog("Choose a File"); open(path) macro "Count particles in ROI - 20X" { original = getImageID() run("Duplicate...", " "); copy = getImageID(); selectImage(copy); run("Median...", "radius=2"); selectImage(original) imageCalculator("Subtract", original,copy); run("Auto Threshold", "method=Triangle dark"); run("From ROI Manager"); name1 = getTitle; dotIndex = indexOf(name1, "."); title1 = substring(name1, 0, dotIndex); n = roiManager("count"); for (i=0; i<n; i++) { roiManager("select", i); run("Analyze Particles...", "size=1-30 circularity=0.00-1.00 show=Nothing display summarize");} selectWindow("Summary"); saveAs("Text",title1); run("Close All"); Thanks for help! Robert -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Robert,
you did not specify a path in the SaveAs command, so the file will go to some default directory. You will probably find it in the ImageJ directory (if it you have write access there; otherwise the file might get lost) or maybe your home directory. Michael ________________________________________________________________ On 11/04/2018 14:42, Robert Niestroj-Pahl wrote: > Hi there, > > I am using ImageJ for a while but only now diving deeper in IJM macro > language. > My Problem: I want to save the "Summary" file output from my macro to a text > file. > The macro works but no text file is generated. I tried several variations, > but nothing worked. Here is my macro: > > run("Close All"); > path = File.openDialog("Choose a File"); > open(path) > macro "DAPI cell count - 20X" { > run("Unsharp Mask...", "radius=1 mask=0.60"); > run("Subtract Background...", "rolling=50"); > run("8-bit"); > setAutoThreshold("Triangle dark"); > //run("Threshold..."); > //setThreshold(50, 255); > setOption("BlackBackground", false); > run("Convert to Mask"); > run("Watershed"); > run("Analyze Particles...", "size=100-Infinity display clear summarize > add"); > close(); > path = File.openDialog("Choose a File"); > open(path) > macro "Count particles in ROI - 20X" { > original = getImageID() > run("Duplicate...", " "); > copy = getImageID(); > selectImage(copy); > run("Median...", "radius=2"); > selectImage(original) > imageCalculator("Subtract", original,copy); > run("Auto Threshold", "method=Triangle dark"); > run("From ROI Manager"); > name1 = getTitle; > dotIndex = indexOf(name1, "."); > title1 = substring(name1, 0, dotIndex); > n = roiManager("count"); > for (i=0; i<n; i++) { > roiManager("select", i); > run("Analyze Particles...", "size=1-30 circularity=0.00-1.00 > show=Nothing display summarize");} > selectWindow("Summary"); > saveAs("Text",title1); > run("Close All"); > > Thanks for help! > > Robert > > > > -- > Sent from: http://imagej.1557.x6.nabble.com/ > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Robert Niestroj-Pahl
Hi Robert, I think the problem is that the Summary window is actually called “Summary of [image name].” Here’s a version of your macro that works for me. ***Make sure to copy the comments at the top and keep them at the very top of the macro. *** These “script parameters” are a handy way to collect file and folder paths. More info: https://imagej.net/Script_Parameters // @File(label = "Input image 1", style = "file") path1 // @File(label = "Input image 2", style = "file") path2 // @File(label = "Output directory", style = "directory") outputDir run("Close All"); //path = File.openDialog("Choose a File"); open(path1) macro "DAPI cell count - 20X" { run("Unsharp Mask...", "radius=1 mask=0.60"); run("Subtract Background...", "rolling=50"); run("8-bit"); setAutoThreshold("Triangle dark"); //run("Threshold..."); //setThreshold(50, 255); setOption("BlackBackground", false); run("Convert to Mask"); run("Watershed"); run("Analyze Particles...", "size=100-Infinity display clear summarize add"); close(); //path = File.openDialog("Choose a File"); open(path2) macro "Count particles in ROI - 20X" { original = getImageID() run("Duplicate...", " "); copy = getImageID(); selectImage(copy); run("Median...", "radius=2"); selectImage(original) imageCalculator("Subtract", original,copy); run("Auto Threshold", "method=Triangle dark"); run("From ROI Manager"); name1 = getTitle; dotIndex = indexOf(name1, "."); title1 = substring(name1, 0, dotIndex); n = roiManager("count"); for (i=0; i<n; i++) { roiManager("select", i); run("Analyze Particles...", "size=1-30 circularity=0.00-1.00 show=Nothing display summarize");} selectWindow("Summary of "+name1); saveAs("Text", outputDir + File.separator + title1 + ".txt"); run("Close All"); Hope this helps. Theresa ------------------------------------ Theresa Swayne, Ph.D. Associate Research Scientist Manager, Confocal and Specialized Microscopy Shared Resource<http://hiccc.columbia.edu/research/sharedresources/confocal> Herbert Irving Comprehensive Cancer Center Columbia University Medical Center 1130 St. Nicholas Ave., Room 222A New York, NY 10032 Phone: 212-851-4613 [hidden email]<mailto:[hidden email]> From: ImageJ Interest Group <[hidden email]> on behalf of Robert Niestroj-Pahl <[hidden email]> Reply-To: "[hidden email]" <[hidden email]> Date: Wednesday, April 11, 2018 at 8:54 AM To: "[hidden email]" <[hidden email]> Subject: Problem with automated file saving Hi there, I am using ImageJ for a while but only now diving deeper in IJM macro language. My Problem: I want to save the "Summary" file output from my macro to a text file. The macro works but no text file is generated. I tried several variations, but nothing worked. Here is my macro: run("Close All"); path = File.openDialog("Choose a File"); open(path) macro "DAPI cell count - 20X" { run("Unsharp Mask...", "radius=1 mask=0.60"); run("Subtract Background...", "rolling=50"); run("8-bit"); setAutoThreshold("Triangle dark"); //run("Threshold..."); //setThreshold(50, 255); setOption("BlackBackground", false); run("Convert to Mask"); run("Watershed"); run("Analyze Particles...", "size=100-Infinity display clear summarize add"); close(); path = File.openDialog("Choose a File"); open(path) macro "Count particles in ROI - 20X" { original = getImageID() run("Duplicate...", " "); copy = getImageID(); selectImage(copy); run("Median...", "radius=2"); selectImage(original) imageCalculator("Subtract", original,copy); run("Auto Threshold", "method=Triangle dark"); run("From ROI Manager"); name1 = getTitle; dotIndex = indexOf(name1, "."); title1 = substring(name1, 0, dotIndex); n = roiManager("count"); for (i=0; i<n; i++) { roiManager("select", i); run("Analyze Particles...", "size=1-30 circularity=0.00-1.00 show=Nothing display summarize");} selectWindow("Summary"); saveAs("Text",title1); run("Close All"); Thanks for help! Robert -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Robert Niestroj-Pahl
> On Apr 11, 2018, at 8:42 AM, Robert Niestroj-Pahl <[hidden email]> wrote:
> > Hi there, > > I am using ImageJ for a while but only now diving deeper in IJM macro > language. > My Problem: I want to save the "Summary" file output from my macro to a text > file. > The macro works but no text file is generated. I tried several variations, > but nothing worked. Here is my macro: The saveAs() function is not passed a full file path so it’s probably saving the text in an unexpected directory. The following example saves the Summary table as a text file using a full file path. -wayne open(""); dir = File.directory; name = File.nameWithoutExtension; savePath = dir + name + ".txt"; setAutoThreshold("Default"); run("Analyze Particles...", "size=1-30 display summarize"); saveAs("Text", savePath); print("name = "+savePath); print("dir = "+dir); print("save path = "+savePath); open(savePath); > > run("Close All"); > path = File.openDialog("Choose a File"); > open(path) > macro "DAPI cell count - 20X" { > run("Unsharp Mask...", "radius=1 mask=0.60"); > run("Subtract Background...", "rolling=50"); > run("8-bit"); > setAutoThreshold("Triangle dark"); > //run("Threshold..."); > //setThreshold(50, 255); > setOption("BlackBackground", false); > run("Convert to Mask"); > run("Watershed"); > run("Analyze Particles...", "size=100-Infinity display clear summarize > add"); > close(); > path = File.openDialog("Choose a File"); > open(path) > macro "Count particles in ROI - 20X" { > original = getImageID() > run("Duplicate...", " "); > copy = getImageID(); > selectImage(copy); > run("Median...", "radius=2"); > selectImage(original) > imageCalculator("Subtract", original,copy); > run("Auto Threshold", "method=Triangle dark"); > run("From ROI Manager"); > name1 = getTitle; > dotIndex = indexOf(name1, "."); > title1 = substring(name1, 0, dotIndex); > n = roiManager("count"); > for (i=0; i<n; i++) { > roiManager("select", i); > run("Analyze Particles...", "size=1-30 circularity=0.00-1.00 > show=Nothing display summarize");} > selectWindow("Summary"); > saveAs("Text",title1); > run("Close All"); > > Thanks for help! > > Robert > > > -- > Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Swayne, Theresa C.
Hi Theresa,
many thanks, that is indeed a very handy way to handle paths! But still, I have a problem. I tried the macro that you wrote, but ImageJ (actually it's Fiji) said: /There is no window with the name Summary of.../ Then I changed the line to selectWindow("Summary"). But then I got another error message, the one I got before: /ImageJ cannot save when file path both contains " " and "]"/ I am using MacOS, is there maybe a problem with file access? Thank you for help, that's a great mailing list! Glad I found this. -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi all,
Problem solved !!!! :-) I realised that I had indeed some rectangle brackets in my file path... Now it works! Robert -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |