How could I get the viewed coordinates?

I am working on viewing large image on napari.
I want to get the data of the displayed area and perform image processing. So I wanted to get only the data of the displayed area, but I don’t know how to do it. It would be nice if I could just get the coordinates, but what should I do?
I know I can get the coordinates of the cursor, but I want to get the coordinates of the corners.

You might be interested in the solution in this post Using napari as a pan-and-zoom-and-crop tool · Issue #1341 · napari/napari · GitHub

The corner pixels of data in a given layer are accessible at layer.corner_pixels. We might change that slightly in the future as we want to remove the knowledge of the viewed data from the layer, but we’ll make sure to continue to provide an easy way to access them.

In that link you can see for example to crop the viewed region of the data you can do

crop = layer.data[tuple(slice(i[0], i[1]) for i in layer.corner_pixels.T)]

Hope that helps!

1 Like

@sofroniewn That’s the answer I wanted! Thank you so much!