Exemplo n.º 1
0
def test_view_shapes(qtbot):
    """Test adding shapes."""
    np.random.seed(0)
    data = 20 * np.random.random((10, 4, 2))
    viewer = napari.view_shapes(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()
Exemplo n.º 2
0
"""
Display one shapes layer ontop of one image layer using the add_shapes and
add_image APIs. When the window is closed it will print the coordinates of
your shapes.
"""

import numpy as np
import napari

with napari.gui_qt():
    path = [[505, 60], [402, 71], [383, 42], [251, 95], [212, 59], [131, 137],
            [126, 187], [191, 204], [171, 248], [211, 260], [273, 243],
            [264, 225], [430, 173], [512, 160]]
    polygons = [path] + [[list(c), [10, 10]] for c in path]
    shape_type = ['path'] + ['ellipse'] * len(path)
    edge_colors = np.random.random((len(polygons), 4))
    napari.view_shapes(polygons,
                       shape_type=shape_type,
                       edge_width=5,
                       opacity=1,
                       edge_color=edge_colors,
                       face_color='royalblue')
Exemplo n.º 3
0
import napari
from neurom.io import swc
import numpy as np

def parse_swc(data):
    break_points = [0] + list(np.nonzero(np.diff(data[:, 6]) < 0)[0]+1) + [len(data)-1]
    paths = []
    for i in range(len(break_points)-1):
        if break_points[i+1] - break_points[i] > 2:
            paths.append(data[break_points[i]:break_points[i+1], :3])
    return paths

# def parse_swc_extra(data):
#     break_points = [0] + list(np.nonzero(np.diff(data[:, 6]) < 0)[0]+1) + [len(data)-1]
#     paths = []
#     for i in range(1, len(break_points)-1):
#         if break_points[i+1] - break_points[i] > 2:
#             paths.append(data[[break_points[i-1], break_points[i]], :3])
#     return paths

data = swc.read('data/neuromorphology/204-2-6nj.CNG.swc').data_block
paths = parse_swc(data)
# extra_paths = parse_swc_extra(data)

with napari.gui_qt():
    # create an empty viewer
    viewer = napari.view_shapes(paths, shape_type='path',
                                edge_color='blue', ndisplay=3)
    # viewer.add_shapes(extra_paths, shape_type='path',
    #                             edge_color='red')
"""
Display one 4-D image layer using the add_image API
"""

import numpy as np
import napari

# create one random polygon per "plane"
planes = np.tile(np.arange(128).reshape((128, 1, 1)), (1, 5, 1))
np.random.seed(0)
corners = np.random.uniform(0, 128, size=(128, 5, 2))
shapes = np.concatenate((planes, corners), axis=2)

base_cols = ['red', 'green', 'blue', 'white', 'yellow', 'magenta', 'cyan']
colors = np.random.choice(base_cols, size=128)

with napari.gui_qt():
    viewer = napari.view_shapes(
        np.array(shapes),
        shape_type='polygon',
        face_color=colors,
        name='sliced',
    )