where x and y are the center points where x-proj and y-proj are the vector projections at each center """ from napari import ViewerApp from napari.util import app_context from skimage import data import numpy as np with app_context(): # create the viewer and window viewer = ViewerApp() layer = viewer.add_image(data.camera(), name='photographer') layer.colormap = 'gray' # sample vector coord-like data n = 1000 pos = np.zeros((n, 4), dtype=np.float32) phi_space = np.linspace(0, 4 * np.pi, n) radius_space = np.linspace(0, 100, n) # assign x-y position pos[:, 0] = radius_space * np.cos(phi_space) + 350 pos[:, 1] = radius_space * np.sin(phi_space) + 256 # assign x-y projection pos[:, 2] = 2 * radius_space * np.cos(phi_space) pos[:, 3] = 2 * radius_space * np.sin(phi_space)
""" from napari import ViewerApp from napari.util import app_context import numpy as np with app_context(): # create the viewer and window viewer = ViewerApp() n = 100 m = 200 image = 0.2*np.random.random((n, m)) + 0.5 layer = viewer.add_image(image, clim_range=[0, 1], name='background') layer.colormap = 'gray' # sample vector image-like data # n x m grid of slanted lines # random data on the open interval (-1, 1) pos = np.zeros(shape=(n, m, 2), dtype=np.float32) rand1 = 2*(np.random.random_sample(n * m)-0.5) rand2 = 2*(np.random.random_sample(n * m)-0.5) # assign projections for each vector pos[:, :, 0] = rand1.reshape((n, m)) pos[:, :, 1] = rand2.reshape((n, m)) # add the vectors vect = viewer.add_vectors(pos, width=0.2, length=2.5)
Display one markers layer ontop of one image layer using the add_markers and add_image APIs """ import numpy as np from skimage import data from skimage.color import rgb2gray from napari import ViewerApp from napari.util import app_context with app_context(): # create the viewer and window viewer = ViewerApp() # add the image viewer.add_image(rgb2gray(data.astronaut())) # add the markers markers = np.array([[100, 100], [200, 200], [333, 111]]) size = np.array([10, 20, 20]) viewer.add_markers(markers, size=size) # unselect the image layer viewer.layers[0].selected = False # adjust some of the marker layer properties layer = viewer.layers[1] # change the layer name layer.name = 'spots' # change the layer visibility
""" Display one 4-D image layer using the add_image API """ import numpy as np from skimage import data from napari import ViewerApp from napari.util import app_context with app_context(): viewer = ViewerApp() blobs = data.binary_blobs(length=128, blob_size_fraction=0.05, n_dim=2, volume_fraction=.25).astype(float) viewer.add_image(blobs, name='blobs') def accept_image(viewer): msg = 'this is a good image' viewer.status = msg print(msg) next(viewer) def reject_image(viewer): msg = 'this is a bad image' viewer.status = msg print(msg) next(viewer) def next(viewer): blobs = data.binary_blobs(length=128, blob_size_fraction=0.05,
your shapes. """ import numpy as np from skimage import data from skimage.color import rgb2gray from napari import ViewerApp from napari.util import app_context from vispy.color import Colormap with app_context(): # create the viewer and window viewer = ViewerApp() # add the image layer = viewer.add_image(data.camera(), name='photographer') layer.colormap = 'gray' # create a list of polygons polygons = [ np.array([[11, 13], [111, 113], [22, 246]]), np.array([[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]]), np.array([[310, 382], [229, 381], [209, 401], [221, 411], [258, 411], [300, 412], [306, 435], [268, 434], [265, 454], [298, 461], [307, 461], [307, 507], [349, 510], [352, 369], [330, 366], [330, 366]]) ] # add polygons