Plugins
Plugins can perform post-processing on reconstructed slices.
Developing a plugin
Developing a post-processing plugin is as easy as implementing a single Python function that takes a 2D numpy array (the reconstructed slice), and returns a 2D numpy array (the postprocessed slice). An example plugin looks like this.
import numpy as np
import slicerecon
from skimage import filters
def callback(shape, xs, _):
# The Otsu implementation does not accept only zeros, so we pass through
if not np.array(xs).any():
return [shape, xs]
# Reshape into an image
xs = np.array(xs).reshape(shape)
# Compute a threshold using Otsu's method
val = filters.threshold_otsu(xs)
# Threshold the image accordingly
xs[xs <= val] = 0.0
xs[xs > val] = 1.0
return [shape, xs.ravel().tolist()]
# Host a plugin on the default port, with the default RECAST3D endpoint
p = slicerecon.plugin("tcp://*:5652", "tcp://localhost:5555")
# Register the callback
p.set_slice_callback(callback)
# Start the plugin
p.listen()
This plugin listens to incoming SliceData
packets on port 5652
, and connects
to a visualization software (or another plugin) listening on port 5555
. These
are the default values. If you use the standard slicerecon_server
program,
connecting the Python plugin is as easy as passing --pyplugin
as a flag.
This plugin computes a simple segmentation based on a threshold computed by Otsu’s method.
Testing your plugin
- Start RECAST3D:
recast3d
- Start
slicerecon_server
, e.g.:
slicerecon_server --slice-size 512 --pyplugin
- Run your plugin, e.g.:
python plugin.py
- Stream projection data to the
slicerecon_server
, e.g.:
python slicerecon_push_flexdata.py [path_to_data] --sample 2
If you make a change to plugin.py
, you can restart it without touching the other components (recast3d, slicerecon) and without restreaming the projection data. Simply request a new reconstruction by modifying a slice (e.g. by clicking on one of the slices in RECAST3D) to see the result.
Example: Otsu thresholding
The example above should give the following visual result.
Dataset: A cone beam scan of a rat skull: doi:10.5281/zenodo.1164088