#!/usr/bin/env python # coding: utf-8 # # Drawing annotations using stackivew # In this notebook we use `stackview.annotate` to create a label image with manual annotations. # In[1]: import stackview import numpy as np from skimage.data import cells3d # The cells3d dataset from scikit-image serves as example image. One of the two channels shown nuclei. # In[2]: image = cells3d()[:,1] stackview.insight(image) # Before annotating the nuclei, we create an empty label image of type unsigned 32-bit integer. This type is necessary so that stackview views the image correctly as labels. Compatible types are: `int32`,`uint32`,`int64`,`uint64`. # In[3]: labels = np.zeros(image.shape).astype(np.uint32) # The function `stackview.annotate` creates a user interface where we can draw labels on top of the original image. Click and drag for drawing. Hold the `ALT` key for erasing. # In[4]: stackview.annotate(image, labels) # You can also annotate in a different plane than the Z-plane by providing an axis (0=z,1=y,2=x). # In[ ]: stackview.annotate(image, labels, axis=1) # Once annotations are drawn, we can view them as usual using the `insight()` function. # In[ ]: stackview.insight(labels) # Just for fun we use the [apoc](https://github.com/haesleinhuepf/apoc) library to create an instance segmentation of nuclei from our annotation. # In[ ]: import apoc segmenter = apoc.ObjectSegmenter(positive_class_identifier=1) features = apoc.PredefinedFeatureSet.small_quick.value segmenter.train(image=image, ground_truth=labels, features=features) result = segmenter.predict(image) stackview.insight(result[30]) # In[ ]: