Hi,
I've written a macro that will save each of the results from my images as separate csv files. However, each time I run this, the dialog box opens upon the get directory command and I keep having to select the output directory before the macro runs. It does this in batch processing too. Is there anyway I can bypass this so all of my csv files save automatically without me having to select the output directory? Thanks in advance Here is my macro: dir = getDirectory("path"); T=getTitle(); name = getTitle; dotIndex = indexOf(name, "."); name = substring(name, 0, dotIndex); setBatchMode(true); selectWindow(T); run("Split Channels"); selectWindow("C3-"+T); rename("BDNF"); run("Red"); selectWindow("C2-"+T); close(); selectWindow("C1-"+T); rename("DAPI"); run("Blue"); //run("Brightness/Contrast..."); run("Enhance Contrast", "saturated=0.35"); run("8-bit"); run("Gaussian Blur...", "sigma=10"); run("Subtract Background...", "rolling=50"); setAutoThreshold("Moments dark"); //run("Threshold..."); setAutoThreshold("Moments dark"); setThreshold(10, 255); //setThreshold(10, 255); run("Convert to Mask"); run("Watershed"); selectWindow("BDNF"); run("8-bit"); run("Subtract Background...", "rolling=16"); run("Mean", "block_radius_x=2 block_radius_y=2"); setAutoThreshold("Moments dark"); //run("Threshold..."); setAutoThreshold("Moments dark"); run("Convert to Mask"); run("Set Measurements...", "area mean standard min integrated redirect=[DAPI] decimal=3"); run("Analyze Particles...", "size=6-150 pixel show=[Overlay Masks] display exclude summarize"); selectWindow("Results"); saveAs("Results", dir + name + ".csv"); |
Good day no-name,
I think dir = getDirectory("path"); is not a valid option. Here is some code snippet that saves the content of the results table to the directory from which you've opened the last image: setBatchMode(true); dir = File.directory; name = File.nameWithoutExtension; run("Measure"); saveAs("results", dir + name + ".csv"); setBatchMode(false); HTH Herbie ::::::::::::::::::::::::::::::::::: Am 18.02.17 um 16:26 schrieb djw23: > Hi, > > I've written a macro that will save each of the results from my images as > separate csv files. However, each time I run this, the dialog box opens > upon the get directory command and I keep having to select the output > directory before the macro runs. It does this in batch processing too. > Is there anyway I can bypass this so all of my csv files save automatically > without me having to select the output directory? > > Thanks in advance > > Here is my macro: > > dir = getDirectory("path"); > T=getTitle(); > name = getTitle; > dotIndex = indexOf(name, "."); > name = substring(name, 0, dotIndex); > setBatchMode(true); > selectWindow(T); > run("Split Channels"); > selectWindow("C3-"+T); > rename("BDNF"); > run("Red"); > selectWindow("C2-"+T); > close(); > selectWindow("C1-"+T); > rename("DAPI"); > run("Blue"); > //run("Brightness/Contrast..."); > run("Enhance Contrast", "saturated=0.35"); > run("8-bit"); > run("Gaussian Blur...", "sigma=10"); > run("Subtract Background...", "rolling=50"); > setAutoThreshold("Moments dark"); > //run("Threshold..."); > setAutoThreshold("Moments dark"); > setThreshold(10, 255); > //setThreshold(10, 255); > run("Convert to Mask"); > run("Watershed"); > selectWindow("BDNF"); > run("8-bit"); > run("Subtract Background...", "rolling=16"); > run("Mean", "block_radius_x=2 block_radius_y=2"); > setAutoThreshold("Moments dark"); > //run("Threshold..."); > setAutoThreshold("Moments dark"); > run("Convert to Mask"); > run("Set Measurements...", "area mean standard min integrated > redirect=[DAPI] decimal=3"); > run("Analyze Particles...", "size=6-150 pixel show=[Overlay Masks] display > exclude summarize"); > selectWindow("Results"); > saveAs("Results", dir + name + ".csv"); > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Saving-results-automatically-without-going-through-save-as-dialog-tp5018135.html > Sent from the ImageJ mailing list archive at 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 djw23
It seems to me that you want to analyse more than one image and looking through your code I think no user interaction is required during the analysis. So it might be possible to select the directory with files you want to analyse and a directory to save the results and analyse all the images in one go.
dirA = getDirectory("path where your files are saved"); dirB = getDirectory("path where you want to save the results"); listA = getFileList(dirA); for(i=0;i<listA.length;i++){ // put between { and } the code you want to use to analyse your images. // You can use run("Analyze Particles...", " show=[Overlay Masks] display exclude clear summarize"); // to delete the results if there is already data in the Results table. // After you have saved the results in dirB close all images using run("Close All"); // It might be necessary to close some other windows, check by running without BatchMode } You also create a summary table you don't seem to use. You can add at the end some code to save this table also automatically. Good luck Kees Dr Ir K.R. Straatman Senior Experimental Officer Advanced Imaging Facility Centre for Core Biotechnology Services University of Leicester http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of djw23 Sent: 18 February 2017 15:27 To: [hidden email] Subject: Saving results automatically without going through save as dialog. Hi, I've written a macro that will save each of the results from my images as separate csv files. However, each time I run this, the dialog box opens upon the get directory command and I keep having to select the output directory before the macro runs. It does this in batch processing too. Is there anyway I can bypass this so all of my csv files save automatically without me having to select the output directory? Thanks in advance Here is my macro: dir = getDirectory("path"); T=getTitle(); name = getTitle; dotIndex = indexOf(name, "."); name = substring(name, 0, dotIndex); setBatchMode(true); selectWindow(T); run("Split Channels"); selectWindow("C3-"+T); rename("BDNF"); run("Red"); selectWindow("C2-"+T); close(); selectWindow("C1-"+T); rename("DAPI"); run("Blue"); //run("Brightness/Contrast..."); run("Enhance Contrast", "saturated=0.35"); run("8-bit"); run("Gaussian Blur...", "sigma=10"); run("Subtract Background...", "rolling=50"); setAutoThreshold("Moments dark"); //run("Threshold..."); setAutoThreshold("Moments dark"); setThreshold(10, 255); //setThreshold(10, 255); run("Convert to Mask"); run("Watershed"); selectWindow("BDNF"); run("8-bit"); run("Subtract Background...", "rolling=16"); run("Mean", "block_radius_x=2 block_radius_y=2"); setAutoThreshold("Moments dark"); //run("Threshold..."); setAutoThreshold("Moments dark"); run("Convert to Mask"); run("Set Measurements...", "area mean standard min integrated redirect=[DAPI] decimal=3"); run("Analyze Particles...", "size=6-150 pixel show=[Overlay Masks] display exclude summarize"); selectWindow("Results"); saveAs("Results", dir + name + ".csv"); -- View this message in context: http://imagej.1557.x6.nabble.com/Saving-results-automatically-without-going-through-save-as-dialog-tp5018135.html Sent from the ImageJ mailing list archive at Nabble.com. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |