def setup(self):
     _ = QApplication.instance() or QApplication([])
     np.random.seed(0)
     self.data = np.random.randint(10, size=(512, 512))
     self.viewer = napari.view_labels(self.data)
     self.layer = self.viewer.layers[0]
     self.layer.brush_size = 10
     self.layer.mode = 'paint'
     self.layer.selected_label = 3
     self.layer._last_cursor_coord = (511, 511)
     Event = collections.namedtuple('Event', 'is_dragging')
     self.event = Event(is_dragging=True)
Пример #2
0
 def setup(self):
     _ = QApplication.instance() or QApplication([])
     np.random.seed(0)
     self.data = np.random.randint(10, size=(512, 512))
     self.viewer = napari.view_labels(self.data)
     self.layer = self.viewer.layers[0]
     self.layer.brush_size = 10
     self.layer.mode = 'paint'
     self.layer.selected_label = 3
     self.layer._last_cursor_coord = (511, 511)
     self.event = MouseEvent(
         type='mouse_move',
         is_dragging=True,
         pos=(500, 500),
         view_direction=None,
     )
Пример #3
0
def test_view_labels(qtbot):
    """Test adding labels image."""
    np.random.seed(0)
    data = np.random.randint(20, size=(10, 15))
    viewer = napari.view_labels(data)
    view = viewer.window.qt_viewer
    qtbot.addWidget(view)

    assert np.all(viewer.layers[0].data == data)

    assert len(viewer.layers) == 1
    assert view.layers.vbox_layout.count() == 2 * len(viewer.layers) + 2

    assert viewer.dims.ndim == 2
    assert view.dims.nsliders == viewer.dims.ndim
    assert np.sum(view.dims._displayed_sliders) == 0

    # Close the viewer
    viewer.window.close()
Пример #4
0
 # Now we want to separate the two objects in image
 # Generate the markers as local maxima of the distance to the background
 distance = ndi.distance_transform_edt(image)
 coords = peak_local_max(distance, footprint=np.ones((3, 3)), labels=image)
 distance = 1 - (distance / distance.max())
 out = watershed(distance, coords, image, 0, affinities=False)
 from train_io import get_affinities
 affs = get_affinities(out.copy())
 from skimage.filters import gaussian
 a_out = watershed(affs.copy(), coords, image, 0, affinities=True)
 affs_g = np.stack(
     [gaussian(affs[i], sigma=1) for i in range(affs.shape[0])])
 ag_out = watershed(affs_g.copy(), coords, image, 0, affinities=True)
 import napari
 v = napari.view_labels(image,
                        name='mask',
                        blending='additive',
                        visible=False)
 v.add_labels(out, name='watershed', blending='additive', visible=False)
 v.add_image(affs[0],
             name='y affinities',
             blending='additive',
             colormap='green',
             visible=False)
 v.add_image(affs[1],
             name='x affinities',
             blending='additive',
             colormap='magenta',
             visible=False)
 v.add_labels(a_out,
              name='affinity watershed',
              blending='additive',
"""
Display a labels layer above of an image layer using the add_labels and
add_image APIs
"""
import numpy as np
from skimage import data
from scipy import ndimage as ndi
import napari

with napari.gui_qt():
    blobs = data.binary_blobs(length=128, volume_fraction=0.1, n_dim=2)
    labeled = ndi.label(blobs)[0]
    viewer = napari.view_labels(labeled, name='blob IDs')
    selection_layer = viewer.add_shapes([[[0, 0], [128, 128]]],
                                        shape_type='rectangle',
                                        face_color=[1, 1, 1, 0],
                                        edge_color=[0, 0.6, 1, 1],
                                        edge_width=1,
                                        name='selection box')

    @viewer.mouse_drag_callbacks.append
    def get_unique_labels(viewer, event):
        yield

        # on move
        while event.type == 'mouse_move':
            labels_layer = viewer.layers[0]
            shapes_layer = viewer.layers[1]
            coords = np.round(shapes_layer.data[0]).astype(int)
            top_left = np.min(coords, axis=0)
            bottom_right = np.max(coords, axis=0)
Пример #6
0
"""
Test adding 4D followed by 5D image layers to the viewer

Intially only 2 sliders should be present, then a third slider should be
created.
"""

import numpy as np
from skimage import data
import napari

with napari.gui_qt():

    viewer = napari.view_labels(np.random.randint(10, size=(1024, 1024)))