| | |
- builtins.object
-
- Cell
- CellsAccessor
class Cell(builtins.object) |
| |
Cell(index=None, bbox=None, position=None, global_segmentation=None, global_image=None, mask=None, rescaled_masks=None, attrs=None)
A cell in a segmentation mask. Can have many attributes describing the
cells shape and position in the image. Some attributes will be inferred when
not specified, eg if only mask16 is specified mask will be provided by scaling
up mask16 to the size of the bounding box
Attributes:
index: int greater than 0
# position attributes (all ndarrays of shape (2,))
position: The centroid position of the cell
size: The size of the bounding box of the cell
point1: same as position
point2: same as position + size
center: same as (point1 + point2) / 2
# shape attributes
# mask attributes
slice: a tuple of slices that can be used to extract a cells bounding box
mask: A boolean mask of the cell inside its bbox
global_mask: A boolean mask of the cell in the whole segmentation map
mask<scale>: A boolean mask of the cell downscaled by scale
segmentation: The segmentation masks cropped to the cells bbox
global_segmentation: The entire segmentation mask
image: phenotyping image cropped to bbox of cell. If it has multiple channels
they will be stored in the first dimension, so shape (C, W, H)
global_image: phenotyping image for whole field. Same as image, channels
are the first axis |
| |
Methods defined here:
- __getattr__(self, name)
- __getitem__(self, name)
- __init__(self, index=None, bbox=None, position=None, global_segmentation=None, global_image=None, mask=None, rescaled_masks=None, attrs=None)
- Initialize self. See help(type(self)) for accurate signature.
- area(self, method='best')
- Returns the area of the cell, based on the method speficied below:
'best': the first method available in this list
'table': the value from an attribute called area
'mask': the sum of the mask
'bbox': the total area of the bounding box
- decode_mask(self, encoded_str, scale)
- encode_mask(self, mask)
- intersection(self, othercell, mask=True)
- Returns a new cell that is only the overlap of the two cells.
The bbox of the new cell is the intersection of the two cells, and if
mask=True the mask of the new cell is the intersection of the two
masks. Can be combined with area() to calculate the overlapping area
of two cells for cell matching or other tasks
- overlap_ratio(self, othercell, method='best')
- plot(self, axes, mask=False, **kwargs)
- Plots this cell at its global position on the passed in Axes object.
If mask=False only the bbox is drawn but if mask=True the mask is
drawn instead.
- rescale_mask(self, scale)
- union(self, othercell, mask=True)
- Returns a new cell that is the union of the two masks.
Readonly properties defined here:
- best_mask
- Returns the highest resolution mask of the cell. If the segmentation
is available, the full mask will be returned, same as self.mask. If the segmentation
is not available but self.rescaled_masks is not empty, the set of masks that are downscaled
the least is returned. The scale of the mask returned can be found with self.best_mask_scale
- best_mask_scale
- The scale of the mask returned by self.best_mask
- center
- global_mask
- has_mask
- image
- mask
- point1
- point2
- position
- segmentation
- size
- slice
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class CellsAccessor(builtins.object) |
| |
CellsAccessor(table)
Accessor to provide attributes and methods to a table containing cells from
a segmentation map
To provide global segmentation masks or phenotype images, directly set the attributes on this accessor:
table.cells.segmentation = segmentation
table.cells.image = phenotype_image
The attributes on this accessor include:
# position and bbox attributes: (bboxes, positions, and sizes are all modifiable, changes will propagate to the table)
bboxes: array of shape (N, 4), the bounding boxes of all cells, ordered (x1, y1, x2, y2)
positions: array of shape (N, 2), the centroid position of all cells
sizes: array of shape (N, 2), the size of the bounding box of all cells
centers: array of shape (N, 2), the centers of the bounding box of all cells
# mask accessors:
masks: pandas.Series() of objects, holding a bool np.array for each cell
best_masks: The highest resolution masks for all cells, either self.mask or self.rescaled_masks[min(self.rescaled_masks)]
best_masks_scale: The level of downscaling of self.best_masks, 1 if self.best_masks is self.masks
rescaled_masks[scale]: pandas.Series() of bool masks for each cell, downscaled by scale |
| |
Methods defined here:
- __getitem__(self, index)
- __init__(self, table)
- Initialize self. See help(type(self)) for accurate signature.
- __iter__(self)
- __len__(self)
- at(self, i)
- decode_masks(self, column, scale)
- encode_masks(self, masks, limit=250)
- intersecting_cells(self, othertable, method='best')
- Finds all cell pairs between this table and othertable that have a nonzero overlapping area.
Returns a new cell table containing the intersection of each cell pair that is overlapping.
The index for the new table is a multiindex with the first level being the index of the cell
from this table, and the second level being the index of the cell from othertable.
method: The method to calculate overlapping area, passed to Cell.area()
- plot(self, axes, masks=False, **kwargs)
- Plot all cells in this table, calls Cell.plot for each one.
If masks=True the masks for each cell are plotted
- rescale_masks(self, scale, limit=250)
- Computes masks for each cell that have been downscaled by scale. These masks
are encoded in base85 and stored as a column in the table. This provides a cheap way
to store the approximate shape of the cell in a tabular format, allowing for comparisons
without having to process the entire cell table. limit sets the limit on the average length
of the base85 encoded strings, to make sure the table doesn't become too large.
Readonly properties defined here:
- bboxes
- best_masks
- best_masks_scale
- centers
- masks
- positions
- sizes
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |