Segmentation

ImagingDataset.segment(method='normcut', label=None, planes=None, **kwargs)

Segment an ImagingDataset to generate ROIs.

Parameters:
  • method ({‘stica’, ‘normcut’, ‘ca1pc’}, optional) – The method for segmentation. Defaults to normcut.
  • label (str, optional) – Label to be associated with the segmented set of ROIs.
  • planes (list of int) – List of the planes that are to be segmented.
  • kwargs (dict) – Additional keyword arguments are passed to the function implementing the selected segmentation method.
Returns:

ROIs (sima.ROI.ROIList) – The segmented regions of interest.

Segmentation approaches

Please consider contributing additional methods to the SIMA project.

Spatialtemporal Independent Component Analysis

sima.segment.stica(dataset, channel=0, mu=0.01, components=75, static_threshold=0.5, min_area=50, x_smoothing=4, overlap_per=0, smooth_rois=True, spatial_sep=True)

Segmentation using spatiotemporial indepenent component analysis (stICA).

Parameters:
  • dataset (sima.ImagingDataset) – dataset to be segmented
  • channel (int, optional) – The index of the channel to be used. Default: 0
  • mu (float, optional) – Weighting parameter for the trade off between spatial and temporal information. Must be between 0 and 1. Low values give higher weight to temporal information. Default: 0.01
  • components (int or list, optional) – Number of principal components to use. If list is given, then use only the principcal componenets indexed by the list Default: 75
  • static_threshold (float, optional) – threhold on the static allowable in an ICA components, eliminating high scoring components speeds the ROI extraction and may improve the results. Default: 0.5
  • min_area (int, optional) – minimum ROI size in number of pixels
  • x_smoothing (int, optional) – number of itereations of static removial and gaussian blur to perform on each stICA component. 0 provides no gaussian blur, larger values produce stICA components with less static but the ROIs loose defination. Default: 5
  • overlap_per (float, optional) – percentage of an ROI that must be covered in order to combine the two segments. Values outside of (0,1] will result in no removal of overlapping ROIs. Requires x_smoothing to be > 0. Default: 0
  • smooth_rois (bool, optional) – Set to True in order to translate the ROIs into polygons and execute smoothing algorithm. Requires x_smoothing to be > 0. Default: True
  • spatial_sep (bool, optional) – If True, the stICA components will be segmented spatially and non-contiguous points will be made into sparate ROIs. Requires x_smoothing to be > 0. Default: True
Returns:

rois (list) – A list of sima.ROI ROI objects

Notes

Spatiotemporal (stICA) [1] is a procedure which applys ICA to extracted PCA components in a process that takes into consideration both the spatial and temporal character of these components. This method has been used to segment calcium imaging data [2], and can be used to segment cell bodies, dendrites, and axons.

In order to implement spatio and temporal ICA, temporal components from PCA are concatenated to the spatial ones. The following spatiotemporal variable \(y_i\) and the resulting ICA components \(z_i\) are defined by:

\[\begin{split}y_i &= \begin{cases} \mu U_{ki} & i \leq N_x \\ (1-\mu)V_{ki} & N_x < i \leq (N_x+N_t) \end{cases} \\ z_i^{k} &= \sum_j \mathbf{W}_{i,j}^{(n)} y^{(j)},\end{split}\]

where \(U\) corresponds to the spatio PCA component matrix with dimensions \(N_x\), pixels, by \(k\) principal components and \(V\) corresponds to the \(N_t\), time frames, by \(k\) temporal PCA component matrix. \(\mu\) is a weighting parameter to balance the tradeoff between the spatio and temporal information with low values of \(\mu\) giving higher weight to the signals temporal components. ICA is performed on \(y_i\) to extract the independent components \(z_i\).

References

[1]Stone JV, Porrill J, Porter NR, Wilkinson ID. Spatiotemporal independent component analysis of event-related fMRI data using skewed probability density functions. Neuroimage. 2002 Feb;15(2):407-21.
[2]Mukamel EA, Nimmerjahn A, Schnitzer MJ. Automated analysis of cellular signals from large-scale calcium imaging data. Neuron. 2009 Sep 24;63(6):747-60.

Normalized cuts

sima.segment.normcut(dataset, channel=0, num_pcs=75, max_dist=None, spatial_decay=None, cut_max_pen=0.01, cut_min_size=40, cut_max_size=200)

Segment image by iteratively performing normalized cuts.

Parameters:
  • dataset (ImagingDataset) – The dataset whose affinity matrix is being calculated.
  • channel (int, optional) – The channel whose signals will be used in the calculations.
  • max_dist (tuple of int, optional) – Defaults to (2, 2).
  • spatial_decay (tuple of int, optional) – Defaults to (2, 2).
  • max_pen (float) – Iterative cutting will continue as long as the cut cost is less than max_pen.
  • cut_min_size, cut_max_size (int) – Regardless of the cut cost, iterative cutting will not be performed on regions with fewer pixels than min_size and will always be performed on regions larger than max_size.
Returns:

list of sima.ROI.ROI – Segmented ROI structures.

Notes

The normalized cut procedure [3] is iteratively applied, first to the entire image, and then to each cut made from the previous application of the procedure.

The affinity \(A_{ij}\) between each pair of pixels \(i,j\) is a function of the correlation \(c_{i,j}\) of the pixel-intensity time series, and the relative locations (\(\mathbf X_i,\mathbf X_j\)) of the pixels:

\[A_{ij} = e^{k_cc_{ij}} \cdot e^{-\frac{|\mathbf X_i-\mathbf X_j|_2^2}{\sigma_{\mathbf X}^2}},\]

with \(k_c\) and \(\sigma_{\mathbf X}^2\) being automatically determined constants.

References

[3]Jianbo Shi and Jitendra Malik. Normalized Cuts and Image Segmentation. IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. 22, NO. 8, AUGUST 2000.

CA1 pyramidal cells

sima.segment.ca1pc(dataset, channel=0, num_pcs=75, max_dist=None, spatial_decay=None, cut_max_pen=0.01, cut_min_size=40, cut_max_size=200, x_diameter=10, y_diameter=10, circularity_threhold=0.5, min_roi_size=20, min_cut_size=30, verbose=False)

Segmentation method designed for finding CA1 pyramidal cell somata.

Parameters:
  • dataset (ImagingDataset) – The dataset whose affinity matrix is being calculated.
  • channel (int, optional) – The channel whose signals will be used in the calculations.
  • max_dist (tuple of int, optional) – Defaults to (2, 2).
  • spatial_decay (tuple of int, optional) – Defaults to (2, 2).
  • max_pen (float) – Iterative cutting will continue as long as the cut cost is less than max_pen.
  • cut_min_size, cut_max_size (int) – Regardless of the cut cost, iterative cutting will not be performed on regions with fewer pixels than min_size and will always be performed on regions larger than max_size.
  • circularity_threhold (float) – ROIs with circularity below threshold are discarded. Default: 0.5.
  • min_roi_size (int, optional) – ROIs with fewer than min_roi_size pixels are discarded. Default: 20.
  • min_cut_size (int, optional) – No ROIs are made from cuts with fewer than min_cut_size pixels. Default: 30.
  • x_diameter (int, optional) – The estimated x-diameter of the nuclei in pixels. Default: 8
  • y_diameter (int, optional) – The estimated x-diameter of the nuclei in pixels. Default: 8
Returns:

list of sima.ROI.ROI – Segmented ROI structures.

Notes

This method begins with the normalized cuts procedure. The affinities used for normalized cuts also depend on the time-averaged image, which is used to increase the affinity between pixels within the same dark patch (putative nucleus).

Following the normalized cut procedure, the algorithm attempts to identify a nucleus within each cut.

  • Otsu thresholding of the time-averaged image after processing with CLAHE and unsharp mask procedures.
  • Binary opening and closing of the resulting ROIs.
  • Rejection of ROIs not passing the circularity and size requirements.

See also

sima.segment.normcut