ROIpy is a python package for ROI (Region of Interest) semi-automatic generation and placement for functional imaging of neuronal dendrites of individual neurons. It provides a tool for defining, managing and visualizing dendritic ROIs. In addition, provides a benchmark for analyzing morphological data such as dendritic structure.
Designed to interface with Vidrio ScanImage software (now MBF).
ROIpy is designed to facilitate scanning along dendritic arborization. In Scanimage, it works for Linear Scan - Frame scan configuration (Galvo-Galvo). ROIpy is developed to overcome the inherent 2D limitation of arbitrary scanning, by generating a set of discrete planes populated with scattered rectangular ROIs spanning the depth of the neuron.
It outputs .roi files which can be loaded and are interpreted by ScanImage mROI Editor Window.
Tested to work with .swc files generated with ImageJ Fiji plugin Simple Neurite Tracer (SNT). .swc files generated with different softwares are not tested and may raise errors. Common labels are apical dendrite or basal dendrite or soma.
Clone the repository and install the package:
git clone https://github.com/dcupolillo/ROIpy.git
cd ROIpy
pip install -e .or optional: you can create a conda environment first:
git clone https://github.com/dcupolillo/ROIpy.git
cd ROIpy
conda env create -f environment.yaml
conda activate roipy
pip install -e .Then restart Python.
ROIpy is composed of 3 main structures: Stack, Morphology, Scanfields. Morphology and Scanfields are further composed of bundles which in turn are formed by individual components.
Represents a stack of images of a given neuron, which includes all dendrites across depth. The initial Stack is acquired using Scanimage Stack Control. Each z-layer defines the discrete planes whereon ROIs will be placed. The stack is necessary to outline the dendritic structure using SNT.
Object defining the digitized structural anatomy of a dendritic arborization (.swc). This object is necessary to drive the placement of dendritic rectangular ROIs.
Represents the ensembles of rotated rectangular ROIs that encapsulate the entire dendritic tree region.
import ROIpy as rp
# Initialize a stack of images of an individual neuron
stack_filename = "path/to/your/stack"
stack = rp.Stack(stack_filename)
# Initialize the morphology with image and tracing files
swc_filename = "path/to/your/swc"
morph = rp.Morphology(swc_filename, stack_filename)
# Initialize the scanfields with image and tracing files
sf = rp.Scanfields(morph)The morphology structure resides in:
nodes_list = morph.neuron
# Indexing to access individual nodes
node = morph.neuron[0]Scanfields are organized in z-planes, wherein individual Roi are nested:
zplanes_containing_rois = sf.neuron
# Indexing to access individual ROIs
roi = sf.meuron[0][0] # first z-plane, first roiYou can visualize any supported structure (Stack, Morphology, Scanfields), bundle (NodeBundle, ScanfieldBundle) or component (Node, Roi) by passing it to plot(). The function automatically dispatches to the correct plotter and supports flexible keyword arguments (**kwargs) for customization.
# Plot the stack image
rp.plot(stack.image, cmap="viridis", norm=(100, 2000))
# Plot the morphology
rp.plot(morph.neuron, show_nodes=True, cmap="jet", segments_kwargs={'linewidth': 1})
# Plot the scanfields
rp.plot(sf.neuron, rect_kwargs={'edgecolor': 'red'})
# 3D plotting example
rp.plot(morph.neuron, projection='3d', show_nodes=True, cmap="jet")If you want to animate 3D visualizations, use the unified animate() function:
morph_anim = rp.animate(
morph.neuron,
flip_yz=True,
axis_label=False,
zoom=2,
cmap="viridis",
show_nodes=True,
show_cbar=True,
save_path="morph_anim.gif")
scanfields_anim = rp.animate(
sf.neuron,
sf.metadata,
cmap="viridis",
show_cbar=True,
axis_label=False,
interval=250,
zoom=1.5,
save_path="scanfields_anim.gif")import ROIpy as rp
rp.run_app()




