How do I retrieve the cursor location coordinates within an image in qupath-m4? I’d like to pass them to the createRectangleROI function to make uniformly-sized objects on click.
Can you just use Objects → Annotations… → Specify annotation?
If you do not specify x and y coordinates, upon pressing Add annotation a fixed-size rectangle will be added based on the viewer center (and repositioned if needed).
Alternatively, you will need to get into JavaFX event filters, intercepting viewer interactions (so that other tools don’t get them) and converting coordinates from the viewer component space to the image pixel space. That would be rather a lot more complicated.
However, I wanted to make an extension which would effectively bypass that popup window. The use-case is manually annotating several ROIs per slide for a dataset containing 100 slides. I was thinking that if I could expose the cursor position information that the other annotation tools are using (e.g., the points tool or the rectangle tool), then I could vastly speed up this process.
So is it perhaps possible to point me to the file which implements the annotation tools? In addition to that, is it possible for me to create a new key binding shortcut to the “specify annotation” window?
The approach that I take in such cases is that I use Specify annotation once, and then use
Shift + D to duplicate the annotation and shift it to the desired location. Then I can do all the repositioning efficiently without needing to interact with menus or buttons or create any further customizations.
I’d recommend trying that first.
If you do decide to try the extension as well, you’ll need to work with the
QuPathViewer.getView() to access the JavaFX component in which the image is displayed. You can there add an
EventHandler, depending upon when you need to be notified) to pick up mouse events, and convert coordinates using methods like this one:
You can get the menu item for the specify command using this script
def menuItem = getQuPath().getMenuItem('Objects>Annotations...>Specify annotation')
and then manipulate that as normal in JavaFX, e.g. add an accelerator.
The Java alternative would be something like
var menuItem = QuPathGUI.getInstance().getMenuItem("Objects>Annotations...>Specify annotation");
The active tool is controlled by a ‘mode’ property (within
QuPathGUI but also available to all open viewers). The current design is a bit convoluted and doesn’t lend itself to being easily extended but I guess there should be ways around it.
In any case, I really wouldn’t recommend staying with v0.2.0-m4, since m8 should be closer to the final stable version (although much work and refactoring remains to be done).