-
Notifications
You must be signed in to change notification settings - Fork 4
5.1 Workflows (Custom workflow)
This section follows on from workflows and will demonstrate how you can generate custom workflows and apply it to your deskewed data within napari-lattice!
We will use examples to demonstrate this.
Image analysis workflows are usually bespoke and although we can generate segmented objects using pyclesperanto-assistant, what if we'd like to perform shape measurements as well?
In the previous section, we performed segmentation using:
- gaussian blur
- voronoi-otsu labelling
Now, we need to measure the shape properties of every label object across time. We will use napari-workflow API to design a workflow where we can callscikit image regionprops at the end to perform measurements.
For executable code and more notes, please refer to this notebook.
We will create a workflow to perform the above segmentation:
#import workflow
from napari_workflows import Workflow
#We initialise a workflow
segmentation_workflow = Workflow()
#Set task for gaussian blur first
input_image = "input_img"
#To set a task, we use the set method
segmentation_workflow.set("gaussian",
cle.gaussian_blur,
source = input_image,
sigma_x = 1,
sigma_y= 1,
sigma_z= 0)
#The second task will use input from above. so set the task name 'gaussian' as input
segmentation_workflow.set("voronoi-otsu",
cle.voronoi_otsu_labeling,
source = "gaussian",
spot_sigma = 14,
outline_sigma=0)
This only gives the images. To extract regionprops, we can write a custom function and save it as a .py
file
from skimage.measure import regionprops_table
import numpy as np
def measure_region_properties(label_img):
label_np = np.array(label_img)
measurements = regionprops_table(label_np, properties=( 'area',
'centroid',
'axis_major_length',
'axis_minor_length'))
return measurements,label_np
This is saved as measure_regionprops.py
. Now, we can import it within our workflow and set it as a task, where the output from voronoi-otsu
m which is a label image is the input for regionprops:
segmentation_workflow.set("region_props",
measure_regionprops.measure_region_properties,
"voronoi-otsu"
)
Save this workflow:
from napari_workflows import _io_yaml_v1
_io_yaml_v1.save_workflow("regionprops_workflow.yml", segmentation_workflow)
To use the segmentation workflow with the custom python module regionprops
, we need to ensure both the regionprops_workflow.yml
file and measure_regionprops.py
are in the same folder. This is ready to be used within napari-lattice
.
Open napari-lattice and initialize your plugin. You can try with test dataset from here.
You can use an ROI from the Crop and Deskew
or just test it on the whole image. Import the workflow and then click Apply and Preview Workflow
This will perform the segmentation and save the regionprops table as a csv
file.
Cellpose is a very popular generalist cell segmentation algorithm. It now has a 'human-in-the-loop' training feature making it relatively easier to generate custom models.