Skip to content

Instantly share code, notes, and snippets.

@psobolewskiPhD
Created April 8, 2024 22:27
script to setup point annotator test
import napari
import numpy as np
from skimage import data
from napari_threedee.annotators import PointAnnotator
from napari_threedee.manipulators import RenderPlaneManipulator
viewer = napari.Viewer()
image_data = data.cells3d()[:,1,...] # just get the one channel
image_layer = viewer.add_image(image_data, name="nuclei", colormap="green")
image_layer.scale = [.5, .25, .25]
viewer.dims.ndisplay = 3
# add_points will yield scale = [1, 1, 1]
pts_layer = viewer.add_points(name="Points", ndim=3)
# set scale
# pts_layer.scale = [.5, .25, .25]
# for easier visualization
plane_layer = viewer.add_image(
image_data,
rendering='average',
name='plane',
colormap='magenta',
blending='additive',
opacity=0.75,
depiction='plane')
plane_layer.scale = image_layer.scale
# create the point annotator, we will use the plane_layer for locations
annotator = PointAnnotator(
viewer=viewer,
image_layer=plane_layer,
points_layer=pts_layer,
enabled=True,
)
# try this plane first, it will work, but if you rotate the points are not on the plane
plane_layer.plane.position = (9, 229, 216)
plane_layer.plane.normal = (0.3, -.7, .7)
napari.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment