Hi
I'm using ImageJ to get point locations via getCursorLoc(x,y,z,flags). Ideally, I'd like to do the following i=0; Macro "doStuff - fancyIconGoesHere"{ i=i+1; getCursorLoc(x,y,z,flags); arrX[i] = x; arrY[i] = y; if(i==4) { //do something here } } However I can't see how to work with the arrX and arrY variables - they can't be created globally. Any thoughts on how to do this without doing it with a java plugin? With thanks in advance C Heeney |
On Tue, Feb 21, 2012 at 12:03 PM, C Heeney <[hidden email]> wrote:
> Hi > > I'm using ImageJ to get point locations via getCursorLoc(x,y,z,flags). > > Ideally, I'd like to do the following > > i=0; > Macro "doStuff - fancyIconGoesHere"{ > i=i+1; > getCursorLoc(x,y,z,flags); > arrX[i] = x; > arrY[i] = y; > if(i==4) > { > //do something here > } > } > > However I can't see how to work with the arrX and arrY variables - they can't be created globally. > Any thoughts on how to do this without doing it with a java plugin? > > With thanks in advance > C Heeney Hi Cheeny, not quite same but the macro I made long time a go might be a good starting point. --- macro "Slice mover [f5]" { requires("1.30e"); leftButton=16; rightButton=4; shift=1; ctrl=2; alt=8; timeout = 8; // seconds startTime = getTime(); x2=-1; y2=-1; z2=-1; getCursorLoc(x, y, z, flags); count=0; while (flags&shift!=1) { getCursorLoc(x, y, z, flags); if (flags&leftButton!=0) { count+=1; print(x+" "+y+" "+z+" "+flags+" "+count); nextslicenum=z+2; makeOval(x-1, y-1, 3, 3); run("Fill","Slice"); op="slice="+nextslicenum; run("Set Slice...", op); run("Select None"); wait(200); } wait(10); } print("Exiting after "+timeout+" seconds of inactivity"); } --- cheers, Kota -- ------------------------------------------------------------- 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 C Heeney
Hi C,
On Tue, 21 Feb 2012, C Heeney wrote: > I'm using ImageJ to get point locations via getCursorLoc(x,y,z,flags). > > Ideally, I'd like to do the following > > i=0; > Macro "doStuff - fancyIconGoesHere"{ > i=i+1; > getCursorLoc(x,y,z,flags); > arrX[i] = x; > arrY[i] = y; > if(i==4) > { > //do something here > } > } > > However I can't see how to work with the arrX and arrY variables - they > can't be created globally. You just have to declare (and even better would be: define) them outside the macro. Note that the feature you are using -- auto-expanding arrays -- is not future-proof. > Any thoughts on how to do this without doing it with a java plugin? You seem to want to do advanced things that are probably more appropriately implemented in a more potent language than ImageJ's macro language. If you are using Fiji, you can use e.g. Beanshell. That language has the advantage that it is very similar to the macro language but also compatible with Java. Should you decide to migrate your code to a proper Java plugin, Beanshell lets you do that gradually (read: painlessly). In Beanshell, you could add a mouselistener or even better, use the AbstractTool framework provided by Fiji. (Recently, ImageJ1 got something similar, with a slightly less -- and of course incompatible -- application programmer interface.) To get started with the AbstractTool framework sounds more horrible than it actually is: in Fiji, just start the Script Editor using File>New>Script, and from the Script Editor's Templates menu, choose Java>Bare Tool. This gives you a Java class implementing a proper Tool; you can run it right away, modify it, run it again, etc Ciao, Johannes |
In reply to this post by C Heeney
On Feb 21, 2012, at 6:03 AM, C Heeney wrote:
> Hi > > I'm using ImageJ to get point locations via getCursorLoc(x,y,z,flags). > > Ideally, I'd like to do the following > > i=0; > Macro "doStuff - fancyIconGoesHere"{ > i=i+1; > getCursorLoc(x,y,z,flags); > arrX[i] = x; > arrY[i] = y; > if(i==4) > { > //do something here > } > } > > However I can't see how to work with the arrX and arrY variables - they can't be created globally. > Any thoughts on how to do this without doing it with a java plugin? Arrays can be created globally in the ImageJ macro language. Here is a macro set containing a tool that adds points to x and y arrays and a macro that resets the arrays. The points are displayed as a multi-point selection so you can see where you clicked. Note that this macro uses expandable arrays so it may not work with ImageJ 2.0. -wayne var xpoints = newArray; var ypoints = newArray; var i = 0; macro "Point Tool - Cf00o2134of033odd33o0a33" { setOption("ExpandableArrays", true); getCursorLoc(x, y, z, flags); xpoints[i] = x; ypoints[i] = y; i++; makeSelection("point", xpoints, ypoints); } macro "Reset Points" { xpoints = newArray; ypoints = newArray; i = 0; run("Select None"); } |
In reply to this post by C Heeney
Thanks Wayne - that works perfectly.
I've only started to use ImageJ recently so I'm still trying to understand how the macros work. The one thing I can't see is how the Reset Macro is called - is it used by the the "Point Tool" macro? Kind regards C Heeney |
On Feb 23, 2012, at 3:24 AM, C Heeney wrote:
> Thanks Wayne - that works perfectly. > > I've only started to use ImageJ recently so I'm still trying to understand how the macros work. The one thing I can't see is how the Reset Macro is called - is it used by the the "Point Tool" macro? The "Reset Points" macro is installed in the Editor's Macros menu, and in the Plugins>Macros menu, as the "Reset Points" command. Here is an updated version of the Point Tool macro set that displays the point count when you double click on the tool icon and resets the arrays if you click "OK" to dismiss the dialog box. -wayne var xpoints = newArray; var ypoints = newArray; var i = 0; macro "Point Tool - Cf00o2134 of033 odd33 o0a33" { setOption("ExpandableArrays", true); getCursorLoc(x, y, z, flags); xpoints[i] = x; ypoints[i] = y; i++; makeSelection("point", xpoints, ypoints); } // Called when user double clicks on the tool icon macro "Point Tool Options" { Dialog.create("Point Tool Options"); n = xpoints.length; Dialog.addMessage("There are currently "+n+" points."); if (n>0) Dialog.addMessage("The arrays will be reset if you click OK."); Dialog.show(); xpoints = newArray; ypoints = newArray; i = 0; run("Select None"); } |
Free forum by Nabble | Edit this page |