Skip to content

Commit

Permalink
Fix wrong working interpolation of labels in 3d (napari#6596)
Browse files Browse the repository at this point in the history
# References and relevant issues

closes napari#6595

# Description

Set interpolation for rendering of 3D data for labels.
  • Loading branch information
Czaki authored Jan 22, 2024
1 parent ded3311 commit 1ee3a39
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions napari/_qt/_tests/test_qt_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,22 @@ def test_background_color(qtbot, qt_viewer: QtViewer, dtype):
)


def test_rendering_interpolation(qtbot, qt_viewer):
data = np.zeros((20, 20, 20), dtype=np.uint8)
data[1:-1, 1:-1, 1:-1] = 5
layer = qt_viewer.viewer.add_labels(
data, opacity=1, rendering="translucent"
)
layer.selected_label = 5
qt_viewer.viewer.dims.ndisplay = 3
QApplication.processEvents()
canvas_screenshot = qt_viewer.screenshot(flash=False)
shape = np.array(canvas_screenshot.shape[:2])
pixel = canvas_screenshot[tuple((shape * 0.5).astype(int))]
color = layer.colormap.map(5)[0] * 255
npt.assert_array_equal(pixel, color)


def test_shortcut_passing(make_napari_viewer):
viewer = make_napari_viewer(ndisplay=3)
layer = viewer.add_labels(
Expand Down
3 changes: 2 additions & 1 deletion napari/_qt/qt_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from weakref import WeakSet, ref

import numpy as np
from qtpy.QtCore import QCoreApplication, QObject, Qt, QUrl
from qtpy.QtGui import QGuiApplication
from qtpy.QtWidgets import QFileDialog, QSplitter, QVBoxLayout, QWidget
Expand Down Expand Up @@ -784,7 +785,7 @@ def _screenshot(self, flash=True):
add_flash_animation(self._welcome_widget)
return img

def screenshot(self, path=None, flash=True):
def screenshot(self, path=None, flash=True) -> np.ndarray:
"""Take currently displayed screen and convert to an image array.
Parameters
Expand Down
1 change: 1 addition & 0 deletions napari/_vispy/layers/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def _setup_nodes(self, texture_format):
),
clim=[0, 2**23 - 1],
texture_format=texture_format,
interpolation='nearest',
)

def get_node(self, ndisplay: int, dtype=None) -> Node:
Expand Down

0 comments on commit 1ee3a39

Please sign in to comment.