How to scroll to a location programmatically

Hi,

I would like to scroll to a particular location in an image window (in zoomed mode or when image doesn’t fit to frame) via macro. Preferentially in Jython/Python. Is this even possible?
Btw, I want to do this, while spots are selected in TrackMate. I guess I should avoid inserting ROI or Overlay.
Thanks

1 Like

Hi @SarenT,

Something that seems to work:

imp = IJ.getImage()
# this tells the canvas to show the part of the image that 
# is 280 by 280 pixels wide, and starting at (200, 200)
imp.getCanvas().setSourceRect( Rectangle( 200, 200, 280, 280) )
imp.draw() # Have to tell the canvas to redraw itself

Older information

The ImageCanvas class has functions that sound like they would do what you want, but they’re “protected”, meaning we can’t call them from the “outside”.

I thought that maybe doing imp.getCanvas().zoomOut(x, y) followed by imp.getCanvas().zoomIn(x, y), could do it, but it doesn’t behave the way I’d expect. (here imp is a variable of type ImagePlus).

Can’t dig into this further now, maybe someone else knows.
John

Edit: found an answer

3 Likes

For whom, who might visit this thread in the future. zoomIn seems to move relatively. To move to a specific spot, one needs to calculate the vector from current location.

2 Likes