fissa.roitools module#

Functions used for ROI manipulation.

Authors:
fissa.roitools.find_roi_edge(mask)[source]#

Find the outline of a mask.

Uses skimage.measure.find_contours().

Parameters
maskarray_like

The mask, as a binary array.

Returns
outlinelist of (n,2)-ndarray

Array with coordinates of pixels in the outline of the mask.

fissa.roitools.get_mask_com(mask)[source]#

Get the center of mass for a boolean mask.

Parameters
maskarray_like

A two-dimensional boolean-mask.

Returns
xfloat

Center of mass along first dimension.

yfloat

Center of mass along second dimension.

fissa.roitools.get_npil_mask(mask, totalexpansion=4)[source]#

Given the masks for a ROI, find the surrounding neuropil.

Our implementation is as follows:

  • On even iterations (where indexing begins at zero), expand the mask in each of the 4 cardinal directions.

  • On odd numbered iterations, expand the mask in each of the 4 diagonal directions.

This procedure generates a neuropil whose shape is similar to the shape of the input ROI mask.

Parameters
maskarray_like

The reference ROI mask to expand the neuropil from. The array should contain only boolean values.

totalexpansionfloat, default=4

How much larger to make the neuropil total area than mask area. Default is 4.

Returns
grown_masknumpy.ndarray

A boolean numpy.ndarray mask, where the region surrounding the input is now True and the region of the input mask is False.

fissa.roitools.getmasks(rois, shpe)[source]#

Get the masks for the specified rois.

Parameters
roisarray_like

List of roi coordinates. Each roi coordinate should be a 2d-array or equivalent list. i.e.: roi = [[0, 0], [0, 1], [1, 1], [1, 0]] or roi = np.array([[0, 0], [0, 1], [1, 1], [1, 0]]) i.e. a n by 2 array, where n is the number of coordinates. If a 2 by n array is given, this will be transposed.

shpearray_like

Shape of underlying image (width, height).

Returns
maskslist of numpy.ndarray

List of masks for each ROI in rois.

fissa.roitools.getmasks_npil(cellMask, nNpil=4, expansion=1)[source]#

Generate neuropil masks using get_npil_mask() function.

Parameters
cellMaskarray_like

The cell mask (boolean 2d arrays).

nNpilint, default=4

Number of neuropil subregions. Default is 4.

expansionfloat, default=1

Area of each neuropil region, relative to the area of cellMask. Default is 1.

Returns
masks_splitlist

Returns a list with soma and neuropil masks (boolean 2d arrays).

fissa.roitools.readrois(roiset)[source]#

Read ImageJ rois from a roiset zipfile.

We ensure that the third dimension (i.e. frame number) is always zero.

Parameters
roisetstr

Path to a roiset zipfile.

Returns
roislist

The ROIs (regions of interest) from within roiset, as polygons describing the outline of each ROI.

fissa.roitools.rois2masks(rois, shape)[source]#

Convert ROIs into a list of binary masks.

Parameters
roisstr or list of array_like

Either a string containing a path to an ImageJ roi zip file, or a list of arrays encoding polygons, or list of binary arrays representing masks.

shapearray_like

Image shape as a length 2 vector.

Returns
maskslist of numpy.ndarray

List of binary arrays.

fissa.roitools.shift_2d_array(a, shift=1, axis=0)[source]#

Shift array values, without wrap around.

Parameters
aarray_like

Input array.

shiftint, default=1

How much to shift array by. Default is 1.

axisint, default=0

The axis along which elements are shifted. Default is 0.

Returns
outnumpy.ndarray

Array with the same shape as a, but shifted appropriately.

fissa.roitools.split_npil(mask, centre, num_slices, adaptive_num=False)[source]#

Split a mask into approximately equal slices by area around its center.

Parameters
maskarray_like

Mask as a 2d boolean array.

centretuple

The center co-ordinates around which the mask will be split.

num_slicesint

The number of slices into which the mask will be divided.

adaptive_numbool, optional

If True, the num_slices input is treated as the number of slices to use if the ROI is surrounded by valid pixels, and automatically reduces the number of slices if it is on the boundary of the sampled region.

Returns
maskslist

A list with num_slices many masks, each of which is a 2d boolean numpy array.