コード例 #1
0
    layer.edge_width = 5
    layer.opacity = 0.75
    layer.selected_shapes = []

    # add an ellipse to the layer
    ellipse = np.array([[59, 222], [110, 289], [170, 243], [119, 176]])
    layer.add_shapes(ellipse,
                     shape_type='ellipse',
                     edge_width=5,
                     edge_color='coral',
                     face_color='purple',
                     opacity=0.75)
    layer.refresh()

    layer._qt_properties.setExpanded(True)

    masks = layer.data.to_masks([512, 512])
    masks_layer = viewer.add_image(masks.astype(float), name='masks')
    masks_layer.opacity = 0.7
    masks_layer.colormap = Colormap([[0.0, 0.0, 0.0, 0.0],
                                     [1.0, 0.0, 0.0, 1.0]])

    labels = layer.data.to_labels([512, 512])
    labels_layer = viewer.add_labels(labels, name='labels')
    labels_layer.visible = False

    svg = layer.to_svg()
    # To save svg file
    # with open('shape.svg', 'w') as f:
    #     f.write(svg)
コード例 #2
0
"""
Display a labels layer above of an image layer using the add_labels and
add_image APIs
"""

from skimage import data
from scipy import ndimage as ndi
from napari import ViewerApp
from napari.util import app_context

with app_context():
    blobs = data.binary_blobs(length=128, volume_fraction=0.1, n_dim=3)
    v = ViewerApp(blobs=blobs)
    v.layers[0].colormap = 'gray'
    labeled = ndi.label(blobs)[0]
    label_layer = v.add_labels(labeled, name='blob ID')
コード例 #3
0
add_image APIs
"""

from skimage import data
from skimage.filters import threshold_otsu
from skimage.segmentation import clear_border
from skimage.measure import label
from skimage.morphology import closing, square, remove_small_objects
from napari import ViewerApp
from napari.util import app_context

with app_context():
    image = data.coins()[50:-50, 50:-50]

    # apply threshold
    thresh = threshold_otsu(image)
    bw = closing(image > thresh, square(4))

    # remove artifacts connected to image border
    cleared = remove_small_objects(clear_border(bw), 20)

    # label image regions
    label_image = label(cleared)

    # initialise viewer with astro image
    viewer = ViewerApp(coins=image, multichannel=False)
    viewer.layers[0].colormap = 'gray'

    # add the labels
    label_layer = viewer.add_labels(label_image, name='segmentation')