I have a collection and macros and functions in a single macro text file. I
would now like to translate these routines into a toolset, which requires making a single macro file for each operation and saving it in the ImageJ/plugins folder. The original approach allowed different macros to use common functions, but it seems that an individual tool must be completely self-contained. I was hoping that I could install a macro containing all common functions that would be accessible to tool macros but this does not work. In general, it appears that only a single macro file can be installed at a time. Is there a way to do this? I don't want to have multiple instances of the same functions in different macro files. thanks! |
On Jul 31, 2009, at 10:00 AM, Benjamin Gilbert wrote:
> I have a collection and macros and functions in a single macro text > file. I > would now like to translate these routines into a toolset, which > requires > making a single macro file for each operation and saving it in the > ImageJ/plugins folder. > > The original approach allowed different macros to use common > functions, but > it seems that an individual tool must be completely self-contained. > I was > hoping that I could install a macro containing all common functions > that > would be accessible to tool macros but this does not work. In > general, it > appears that only a single macro file can be installed at a time. > > Is there a way to do this? I don't want to have multiple instances > of the > same functions in different macro files. You can do this by adding the common functions to the macro language by calling the Interpreter.setAdditionalFunctions() method. Here is an example. Create a folder in the plugins folder named MyMacros. Add these three files (CommonFunctions, Macro1 and Macro2) to it: CommonFunctions.txt function f1() { print("f1"); } function f2() { print("f2"); } Macro1.ijm print("Macro1"); f1(); f2(); Macro2.ijm print("Macro2"); f1(); f2(); Then add this code to the StartupMacros file (Plugins>Macros>StartupMacros) macro "AutoRun" { path = getDirectory("plugins")+"MyMacros/CommonFunctions.txt"; functions = File.openAsString(path); call("ij.macro.Interpreter.setAdditionalFunctions", functions); } save it and restart ImageJ. You will now have two commands (Macro1 and Macro2) in the Plugins>MyMacros submenu implemented by macros that share the functions in CommonFunctions. CommonFunctions has a .txt extension and no underscore in the name so it does not appear in the Plugins>MyPlugins submenu. Macro1 and Macro2 have .ijm (ImageJ Macro) extensions so they do appear even though they do not have an underscore in the name. You may decide that it's easier and better to keep the functions and macros in a single file (toolset) located in the ImageJ/macros/ toolsets folder. That way the macros and functions can share global variables, you can easily add keyboard shortcuts, the toolset can contain tools, toolbar menus and action tools as well as macros, and you can have multiple toolsets, selected from the ">>" toolbar menu. -wayne |
Thanks for the very clear reply. I learnt how to store global
variables from an earlier post to the list using call("ij.Prefs.get", <key>, <value>) ... but perhaps a single toolset would be a simpler approach! Is there likely to be support for multivariate fit functions in the near future? I would like to fit a 2D polynomial to make an image background. many thanks ben At 4:18 PM -0400 8/1/09, Wayne Rasband wrote: >On Jul 31, 2009, at 10:00 AM, Benjamin Gilbert wrote: > >>I have a collection and macros and functions in a single macro text file. I >>would now like to translate these routines into a toolset, which requires >>making a single macro file for each operation and saving it in the >>ImageJ/plugins folder. >> >>The original approach allowed different macros to use common functions, but >>it seems that an individual tool must be completely self-contained. I was >>hoping that I could install a macro containing all common functions that >>would be accessible to tool macros but this does not work. In general, it >>appears that only a single macro file can be installed at a time. >> >>Is there a way to do this? I don't want to have multiple instances of the >>same functions in different macro files. > >You can do this by adding the common functions to the macro language >by calling the Interpreter.setAdditionalFunctions() method. Here is >an example. > >Create a folder in the plugins folder named MyMacros. Add these >three files (CommonFunctions, Macro1 and Macro2) to it: > > CommonFunctions.txt > > function f1() { > print("f1"); > } > function f2() { > print("f2"); > } > > Macro1.ijm > > print("Macro1"); > f1(); > f2(); > > Macro2.ijm > > print("Macro2"); > f1(); > f2(); > >Then add this code to the StartupMacros file (Plugins>Macros>StartupMacros) > > macro "AutoRun" { > path = getDirectory("plugins")+"MyMacros/CommonFunctions.txt"; > functions = File.openAsString(path); > call("ij.macro.Interpreter.setAdditionalFunctions", functions); > } > >save it and restart ImageJ. You will now have two commands (Macro1 >and Macro2) in the Plugins>MyMacros submenu implemented by macros >that share the functions in CommonFunctions. CommonFunctions has a >.txt extension and no underscore in the name so it does not appear >in the Plugins>MyPlugins submenu. Macro1 and Macro2 have .ijm >(ImageJ Macro) extensions so they do appear even though they do not >have an underscore in the name. > >You may decide that it's easier and better to keep the functions and >macros in a single file (toolset) located in the >ImageJ/macros/toolsets folder. That way the macros and functions can >share global variables, you can easily add keyboard shortcuts, the >toolset can contain tools, toolbar menus and action tools as well as >macros, and you can have multiple toolsets, selected from the ">>" >toolbar menu. > >-wayne -- Benjamin Gilbert Scientist, Earth Science Division Lawrence Berkeley National Laboratory 1 Cyclotron Road MS 90R1116 Berkeley, CA 94720 USA [hidden email] http://nanogeoscience.berkeley.edu Office: 90 1143 Lab: 70 158 Office: 1-510 495 2748 Lab: 1-510 486 4424 Cell: 1-608 358 0194 Fax: 1-510 486 5686 |
On Aug 2, 2009, at 4:45 PM, Benjamin Gilbert wrote:
> Thanks for the very clear reply. I learnt how to store global > variables from an earlier post to the list using > call("ij.Prefs.get", <key>, <value>) ... but perhaps a single > toolset would be a simpler approach! > > Is there likely to be support for multivariate fit functions in the > near future? I would like to fit a 2D polynomial to make an image > background. The Nonuniform Background Removal plugin at http://www.cs.unc.edu/~cquammen/imagej/nonuniform_background_removal.html uses the JAMA package (http://math.nist.gov/javanumerics/jama/) to fit 2D cubic polynomials to images. The installation instructions say to copy Jama-1.0.2.jar to ImageJ/jre/lib/ext but it also works if you copy it to the plugins folder. -wayne |
In reply to this post by Benjamin Gilbert
Hi Ben,
you can do this directly with the Fit_Polynomial plugin. http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:fit_polynomial:start The plugin uses the old approach for a linear fit, from the days of programmable pocket calculators: Creating a matrix, and a very simple matrix inversion algorithm. For well-behaved problems, with fit parameters having the same order of magnitude, it is works well up to a few dozen fit parameters. Otherwise, more elaborate methods such as in the JAMA package are needed. Michael ______________________________________________________________________ On Sun, August 2, 2009 22:45, Benjamin Gilbert wrote: > Is there likely to be support for multivariate fit functions in the > near future? I would like to fit a 2D polynomial to make an image > background. > > many thanks > > ben |
Free forum by Nabble | Edit this page |