Skip to content

Instantly share code, notes, and snippets.

@alisterburt
Created June 23, 2022 16:02
Show Gist options
  • Select an option

  • Save alisterburt/5796f80d2a94d13617bf5f2f1368ae63 to your computer and use it in GitHub Desktop.

Select an option

Save alisterburt/5796f80d2a94d13617bf5f2f1368ae63 to your computer and use it in GitHub Desktop.
find edge of a label in python
import napari
import numpy as np
import scipy.ndimage as ndi
SIZE = 42
# small circle
circle = np.linalg.norm(
np.indices(dimensions=(SIZE, SIZE)) - (SIZE / 2), axis=0
) < SIZE / 4
# find edge of circle
edt = ndi.distance_transform_edt(circle)
edge = np.logical_and(edt < 2, edt != 0)
# view in napari
viewer = napari.Viewer()
viewer.add_image(edge)
viewer.add_image(edt)
viewer.add_image(circle)
viewer.text_overlay.text = 'circle -> edt -> edge'
viewer.text_overlay.font_size = 20
viewer.text_overlay.visible = True
viewer.grid.shape = (1, 3)
viewer.grid.enabled = True
napari.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment