Hello,
I am using ImageJ from the R language on OSX operating system by the following example code: system("./JavaApplicationStub directory file[i] -batch zmacro") I run this code within a loop in R so that the macro "zmacro" is run on all images. However, I wonder if I can get this to run in the background. That is, each iteration, ImageJ opens, opens the image and runs the macro, then closes ImageJ. And repeat for each image. This makes it hard to do anything else during this for loop because ImageJ keeps becoming the active window, then closes, etc.. I wonder if I can modify the macro code or the code above to make ImageJ either only open once and then close after all images are done, or just not open and run in the background. Here is my macro code in case that helps: // count pollen grains - black/whtie pictures macro "CountBWPollenGrains [z]" { title = getTitle; dir = "/Mac2/Images/Pollen_grains/Images/"; run("Subtract Background...", "rolling=100"); run("Invert"); setAutoThreshold("Yen"); run("Convert to Mask"); run("Watershed"); run("Analyze Particles...", "size=40-120 circularity=0.5-1.00 show=Masks summarize"); saveAs("Measurements", dir + title + ".txt"); run("Close"); } Cheers, Scott Chamberlain Rice Univ. |
Hi Scott,
One way is to include the batch processing within your ImageJ macro. This could be done by 1. Get a list of all file names within the target directory using getFileList(dir) command. see http://rsbweb.nih.gov/ij/developer/macro/functions.html#getFileList 2. then loop through the file name array and do the processing. so something like files = getFileList(dir); for (i = 0; i < files.length; i++){ open(dir + <File.separator> + files[i]); ... <your processing>; close(); } Another way is to write a javascript. With this (or other available scripting languages if you are using Fiji), you could do the same thing without even opening the ImageJ GUI, completely silent. cheers, Kota On Thu, Mar 15, 2012 at 7:14 PM, Scott Chamberlain <[hidden email]> wrote: > Hello, > > > I am using ImageJ from the R language on OSX operating system by the following example code: > > system("./JavaApplicationStub directory file[i] -batch zmacro") > > > I run this code within a loop in R so that the macro "zmacro" is run on all images. > > However, I wonder if I can get this to run in the background. That is, each iteration, ImageJ opens, opens the image and runs the macro, then closes ImageJ. And repeat for each image. This makes it hard to do anything else during this for loop because ImageJ keeps becoming the active window, then closes, etc.. I wonder if I can modify the macro code or the code above to make ImageJ either only open once and then close after all images are done, or just not open and run in the background. > > > > Here is my macro code in case that helps: > > // count pollen grains - black/whtie pictures > macro "CountBWPollenGrains [z]" { > title = getTitle; > dir = "/Mac2/Images/Pollen_grains/Images/"; > run("Subtract Background...", "rolling=100"); > run("Invert"); > setAutoThreshold("Yen"); > run("Convert to Mask"); > run("Watershed"); > run("Analyze Particles...", "size=40-120 circularity=0.5-1.00 show=Masks summarize"); > saveAs("Measurements", dir + title + ".txt"); > run("Close"); > } > > > > Cheers, > Scott Chamberlain > Rice Univ. -- ------------------------------------------------------------- Dr. Kota Miura Scientist & IT Engineer Centre for Molecular and Cellular Imaging, European Molecular Biology Laboratory Meyerhofstr. 1 69117 Heidelberg GERMANY Tel +49 6221 387 404 Mobile +49 160 95001177 Fax +49 6221 387 512 http://cmci.embl.de ------------------------------------------------------------- |
In reply to this post by schamber789
Hello Scott:
[apologies if this has already been answered - I use digest mode...] The -batch option basically tells ImageJ to do exactly what you have observed: start - run macro - quit so you have the Java + ImageJ start-up overhead every time = long! We have utilized ImageJ as an image-analysis server by enabling the "Run single instance listener" option (Edit->Options->Misc... ), then running a macro from the command line with either the -eval or the -macro option. Your first invocation will start ImageJ, so it will take the usual start-up time, but subsequent calls will be intercepted by the listener and run directly. If you include the setBatchMode() instructions in your macro, then you should get the benefit of "nearly-headless" operation of ImageJ. In our case, we are actually running a plugin that explicitly does NOT display images, results, etc. We treat it as a background process in a larger piece of instrumentation. That is, it doesn't constantly insist on being the active window, so we more-or-less ignore it. We've only seen minor execution time differences between running things as an internal ImageJ loop compared to having a command line procedure initiate the macro. Most of that time difference is just the mechanism of executing the command line call from one program, having the operating system pass it off, then receiving the command in ImageJ. Hope this helps. Bill William A. Heeschen, Ph.D. Microscopy, Digital Imaging The Dow Chemical Company Midland, MI 48667 [hidden email] Date: Thu, 15 Mar 2012 13:14:49 -0500 From: Scott Chamberlain <[hidden email]> Subject: ImageJ from R - problem Hello, I am using ImageJ from the R language on OSX operating system by the following example code: system("./JavaApplicationStub directory file[i] -batch zmacro") I run this code within a loop in R so that the macro "zmacro" is run on all images. However, I wonder if I can get this to run in the background. That is, each iteration, ImageJ opens, opens the image and runs the macro, then closes ImageJ. And repeat for each image. This makes it hard to do anything else during this for loop because ImageJ keeps becoming the active window, then closes, etc.. I wonder if I can modify the macro code or the code above to make ImageJ either only open once and then close after all images are done, or just not open and run in the background. Here is my macro code in case that helps: // count pollen grains - black/whtie pictures macro "CountBWPollenGrains [z]" { title = getTitle; dir = "/Mac2/Images/Pollen_grains/Images/"; run("Subtract Background...", "rolling=100"); run("Invert"); setAutoThreshold("Yen"); run("Convert to Mask"); run("Watershed"); run("Analyze Particles...", "size=40-120 circularity=0.5-1.00 show=Masks summarize"); saveAs("Measurements", dir + title + ".txt"); run("Close"); } Cheers, Scott Chamberlain Rice Univ. |
Free forum by Nabble | Edit this page |