Point coordinates from ImageJ canvas

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Point coordinates from ImageJ canvas

Jprada
Hello

I am trying to get the coordinates from a mouse click in the ImageJ canvas and then pass them to R. I have been reading these two sources, am I on the right direction? is there any example showing this feature?

http://rsb.info.nih.gov/ij/developer/macro/macros.html#tools

http://rsb.info.nih.gov/ij/developer/api/ij/plugin/tool/PixelInspectionTool.html#mousePressed-ij.ImagePlus-java.awt.event.MouseEvent-

Thanks
Juan
Reply | Threaded
Open this post in threaded view
|

Re: Point coordinates from ImageJ canvas

Marcel
Hello Juan,

you can use two available functions in Bio7 (Image-Methods dialog) to transfer point coordinates directly to R.

Without the ROI-Manager just press Shift and click some point selections. Transfer them with the "Points" action or use the ROI Manager with the "Selection" action. With the ROI-Manager multiple slices can be transferred, too. For both see:

https://www.youtube.com/watch?v=_E16ZbYzxRg

In addition you can transfer the selections as a SpatialPoints(DataFrame) object, see:

https://www.youtube.com/watch?v=7t5V2o8jFJw

Of course you can create a plugin to do this, too.

But do you really need this?

ImageJ plugins can be compiled dynamically with Bio7 and can use the Rserve API.

See this example for a mouse listener plugin which can be combined with thr Rserve API:

http://rsb.info.nih.gov/ij/plugins/download/Mouse_Listener.java

Simply create an empty Bio7 Java project and then open the Java perspective.

Copy the code and paste it in the src package (JDT will create the class for you).

Then compile dynamically, open an image and then click on the image.



Reply | Threaded
Open this post in threaded view
|

Re: Point coordinates from ImageJ canvas

Jprada
Thanks Marcel, the example is working.
How can I pass a variable or a value by code to R? for example if I wanted to pass the coordinates of the point where I clicked.

I tried this "RServe.assign("frame", slice);" to pass the number of the current slice in the video but it did not work.

Best
Juan
Reply | Threaded
Open this post in threaded view
|

Re: Point coordinates from ImageJ canvas

Marcel
Here a simple example for single values:

RConnection c = RServe.getConnection();
ImageProcessor ip = imp.getProcessor();
int w = ip.getWidth();
int h = ip.getHeight();

try {
        c.eval("imageSizeY<-" + h);
        c.eval("imageSizeX<-" + w);

.................................................................................

In addition here you find various other examples to assign arrays etc. (regular Rserve examples on the Github Rserve repo):

https://github.com/s-u/REngine/blob/master/Rserve/test/test.java


Besides I also have an special Bio7 API available, see the Bio7 API docs in the Bio7 help (class RScript)