# Visualizing region properties in napari#

Visualizing quantitative measurements of regions in color on top of the regions is a common task when using napari. The napari plugin napari-skimage-regionprops brings some convenience in drawing such parametric images.

from skimage.io import imread
from skimage.filters import threshold_otsu
from skimage.measure import label, regionprops_table
import napari


image = imread('../../data/blobs.tif')

# Create an empty viewer
viewer = napari.Viewer()

/Users/haase/opt/anaconda3/envs/bio_39/lib/python3.9/site-packages/napari_tools_menu/__init__.py:168: FutureWarning: Public access to Window.qt_viewer is deprecated and will be removed in
v0.5.0. It is considered an "implementation detail" of the napari
application, not part of the napari viewer model. If your use case

# Add a new layer containing an image

napari.utils.nbscreenshot(viewer)


Next, we segment blobs in the image and create a label image.

# segment and label blobs
threshold = threshold_otsu(image)
binary_image = image > threshold
label_image = label(binary_image)

napari.utils.nbscreenshot(viewer)


## Quantitative measurements#

We now extract quantiative measurements from the label image, e.g. by measuring the area of the labeled objects. For that we use scikit-image’s regionprops_table function. We save those statistical measurements in the label layer’s properties so that napari and napari-plugins can post-process the data.

# measure region properties
statistics = regionprops_table(label_image, properties=['area'])

# save properties in the labels layer for later reuse
label_layer.properties = statistics


We then use the scriptable napari plugin napari-skimage-regionprops to visualize the measurements in a parametric_image and add that image to the napari viewer as well.

parametric_image = visualize_measurement_on_labels(label_layer, 'area')

napari.utils.nbscreenshot(viewer)


We can also visualize the measurements as table using the add_table function of the same napari plugin.

add_table(label_layer, viewer)

napari.utils.nbscreenshot(viewer)


## Exercise#

Measure the aspect ratio of the objects and visualize the values in color.