allensdk.brain_observatory.roi_masks module¶
- class allensdk.brain_observatory.roi_masks.Mask(image_w, image_h, label, mask_group)[source]¶
Bases:
object
Abstract class to represent image segmentation mask. Its two main subclasses are RoiMask and NeuropilMask. The former represents the mask of a region of interest (ROI), such as a cell observed in 2-photon imaging. The latter represents the neuropil around that cell, and is useful when subtracting the neuropil signal from the measured ROI signal.
This class should not be instantiated directly.
- Parameters:
- image_w: integer
Width of image that ROI resides in
- image_h: integer
Height of image that ROI resides in
- label: text
User-defined text label to identify mask
- mask_group: integer
User-defined number to help put masks into different categories
- get_mask_plane()[source]¶
Returns mask content on full-size image plane
- Returns:
- numpy 2D array [img_rows][img_cols]
- init_by_pixels(border, pix_list)[source]¶
Initialize mask using a list of mask pixels
- Parameters:
- border: float[4]
Coordinates defining useable area of image. See create_roi_mask()
- pix_list: integer[][2]
List of pixel coordinates (x,y) that define the mask
- property overlaps_motion_border¶
- class allensdk.brain_observatory.roi_masks.NeuropilMask(w, h, label, mask_group)[source]¶
Bases:
Mask
- init_by_mask(border, array)[source]¶
Initialize mask using spatial mask
- Parameters:
- border: float[4]
Border widths on the [right, left, down, up] sides. The resulting neuropil mask will not include pixels falling into a border.
- array: integer[image height][image width]
Image-sized array that describes the mask. Active parts of the mask should have values >0. Background pixels must be zero
- class allensdk.brain_observatory.roi_masks.RoiMask(image_w, image_h, label, mask_group)[source]¶
Bases:
Mask
- init_by_mask(border, array)[source]¶
Initialize mask using spatial mask
- Parameters:
- border: float[4]
Coordinates defining useable area of image. See create_roi_mask().
- roi_mask: integer[image height][image width]
Image-sized array that describes the mask. Active parts of the mask should have values >0. Background pixels must be zero
- allensdk.brain_observatory.roi_masks.calculate_roi_and_neuropil_traces(movie_h5, roi_mask_list, motion_border)[source]¶
get roi and neuropil masks
- allensdk.brain_observatory.roi_masks.calculate_traces(stack, mask_list, block_size=1000)[source]¶
Calculates the average response of the specified masks in the image stack
- Parameters:
- stack: float[image height][image width]
Image stack that masks are applied to
- mask_list: list<Mask>
List of masks
- Returns:
- float[number masks][number frames]
This is the average response for each Mask in each image frame
- allensdk.brain_observatory.roi_masks.create_neuropil_mask(roi, border, combined_binary_mask, label=None)[source]¶
Conveninece function to create and initializes a Neuropil mask. Neuropil masks are defined as the region around an ROI, up to 13 pixels out, that does not include other ROIs
- Parameters:
- roi: RoiMask object
The ROI that the neuropil masks will be based on
- border: float[4]
Border widths on the [right, left, down, up] sides. The resulting neuropil mask will not include pixels falling into a border.
- combined_binary_mask
List of pixel coordinates (x,y) that define the mask
- combined_binary_mask: integer[image_h][image_w]
Image-sized array that shows the position of all ROIs in the image. ROI masks should have a value of one. Background pixels must be zero. In other words, ithe combined_binary_mask is a bitmap union of all ROI masks
- label: text
User-defined text label to identify the mask
- Returns:
- NeuropilMask object
- allensdk.brain_observatory.roi_masks.create_roi_mask(image_w, image_h, border, pix_list=None, roi_mask=None, label=None, mask_group=-1)[source]¶
Conveninece function to create and initializes an RoiMask
- Parameters:
- image_w: integer
Width of image that ROI resides in
- image_h: integer
Height of image that ROI resides in
- border: float[4]
Coordinates defining useable area of image. If the entire image is usable, and masks are valid anywhere in the image, this should be [0, 0, 0, 0]. The following constants help describe the array order:
RIGHT_SHIFT = 0
LEFT_SHIFT = 1
DOWN_SHIFT = 2
UP_SHIFT = 3
When parts of the image are unusable, for example due motion correction shifting of different image frames, the border array should store the usable image area
- pix_list: integer[][2]
List of pixel coordinates (x,y) that define the mask
- roi_mask: integer[image_h][image_w]
Image-sized array that describes the mask. Active parts of the mask should have values >0. Background pixels must be zero
- label: text
User-defined text label to identify mask
- mask_group: integer
User-defined number to help put masks into different categories
- Returns:
- RoiMask object