Napari: Cursor coordinates are off by 0.5

Created on 29 May 2019  ·  3Comments  ·  Source: napari/napari

🐛 Bug

The coordinates at the center of pixel [0, 0] should be [0, 0]. When looking at a tiny image, hovering over the pixels and looking at the value in the status bar, it is clear that the cursor coordinates are offset by 0.5 along each axis relative to the image:

pix2
pix1
pix3
pix5

To Reproduce

import numpy as np
import napari
import napari.util


image = np.array([[0, 0, 0, 1],
                  [0, 0, 1, 1],
                  [1, 0, 0, 0],
                  [0, 1, 0, 0]], dtype=float)

with napari.util.app_context():
    napari.view(image, multichannel=False)  # check that the intensity matches the cursor pos

Expected behavior

With nearest-neighbor / no interpolation, the cursor should display the coordinates of the nearest pixel and the value should be what is displayed under the cursor.

Environment

  • napari Version (e.g., 1.0): master
  • OS (e.g., Linux): Linux
  • Python version: 3.6
  • Any other relevant information:

Additional context

We had some debates about whether to offset by 0.5 or not. I think there are many reasons why the centers of pixels should be at integer coordinates. My two leading ones are:

  • if I put a marker smack in the middle of a pixel, I expect the coordinates of that marker to be integer values, not offset by 0.5.
  • interpolation reduces to indexing when doing so on an integer grid.
bug

All 3 comments

Sounds reasonable, I can look into fixing this and making sure it has no unintended consequences for the markers and shapes layer, where we're already doing some 0.5 offsetting

Note how this appears in matplotlib. We will want to align with this convention across all our layer types.

image

Note: I agree very much about the alignment of voxels and points, but not about the order of axes — plt.scatter(2.3, 0.3) will put the dot on the top right instead of the bottom left.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kevinyamauchi picture kevinyamauchi  ·  4Comments

Czaki picture Czaki  ·  3Comments

tlambert03 picture tlambert03  ·  3Comments

sofroniewn picture sofroniewn  ·  3Comments

JoOkuma picture JoOkuma  ·  3Comments