fissa.roitools module

Functions used for ROI manipulation.

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

Finds the outline of a mask, using the find_contour function from skimage.measure.

Parameters:mask (array_like) – the mask, a binary array
Returns:outline – Array with coordinates of pixels in the outline of the mask
Return type:list of (n,2)-ndarrays
fissa.roitools.get_mask_com(mask)[source]

Get the center of mass for a boolean mask.

Parameters:mask (array_like) – A two-dimensional boolean-mask.
Returns:
  • float – Center of mass along first dimension.
  • float – 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.

Parameters:
  • mask (array_like) – The reference ROI mask to expand the neuropil from. The array should contain only boolean values.
  • expansion (float, optional) – How much larger to make the neuropil total area than mask area.
Returns:

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

Return type:

numpy.ndarray

Notes

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.

Note

For fixed number of iterations, squarer input masks will have larger output neuropil masks.

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

Get the masks for the specified rois.

Parameters:
  • rois (list) – 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.
  • shpe (array/list) – shape of underlying image [width,height]
Returns:

List of masks for each roi in the rois list

Return type:

list of numpy.ndarray

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

Generate neuropil masks using the get_npil_mask function.

Parameters:
  • cellMask (array_like) – the cell mask (boolean 2d arrays)
  • nNpil (int) – number of neuropil subregions
  • expansion (float) – How much larger to make neuropil subregion area than in cellMask
Returns:

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

Return type:

list

fissa.roitools.readrois(roiset)[source]

read the imagej rois in the zipfile roiset, and make sure that the third dimension (i.e. frame number) is always zero.

Parameters:roiset (str) – folder to a zip file with rois
Returns:Returns the rois as polygons
Return type:list
fissa.roitools.shift_2d_array(a, shift=1, axis=None)[source]

Shifts an entire array in the direction of axis by the amount shift, without refilling the array.

Parameters:
  • a (array_like) – Input array.
  • shift (int, optional) – How much to shift array by. Default is 1.
  • axis (int, optional) – The axis along which elements are shifted. By default, the array is flattened before shifting, after which the original shape is restored.
Returns:

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

Return type:

numpy.ndarray

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

Splits a mask into a number of approximately equal slices by area around the center of the mask.

Parameters:
  • mask (array_like) – Mask as a 2d boolean array.
  • centre (tuple) – The center co-ordinates around which the mask will be split.
  • num_slices (int) – The number of slices into which the mask will be divided.
  • adaptive_num (bool, 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:

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

Return type:

list