sopa.segmentation.shapes
sopa.segmentation.shapes.solve_conflicts(cells, threshold=0.5, patch_indices=None, return_indices=False)
Resolve segmentation conflicts (i.e. overlap) after running segmentation on patches
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cells |
list[Polygon]
|
List of cell polygons |
required |
threshold |
float
|
When two cells are overlapping, we look at the area of intersection over the area of the smallest cell. If this value is higher than the |
0.5
|
patch_indices |
ndarray | None
|
Patch from which each cell belongs. |
None
|
return_indices |
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
ndarray[Polygon] | tuple[ndarray[Polygon], ndarray]
|
Array of resolved cells polygons. If |
Source code in sopa/segmentation/shapes.py
sopa.segmentation.shapes.geometrize(mask, tolerance=None, smooth_radius_ratio=0.1)
Convert a cells mask to multiple shapely
geometries. Inspired from https://github.com/Vizgen/vizgen-postprocessing
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask |
ndarray
|
A cell mask. Non-null values correspond to cell ids |
required |
tolerance |
float | None
|
Tolerance parameter used by |
None
|
Returns:
Type | Description |
---|---|
list[Polygon]
|
List of |
Source code in sopa/segmentation/shapes.py
sopa.segmentation.shapes.rasterize(cell, shape, xy_min=[0, 0])
Transform a cell polygon into a numpy array with value 1 where the polygon touches a pixel, else 0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell |
Polygon | MultiPolygon
|
Cell polygon to rasterize. |
required |
shape |
tuple[int, int]
|
Image shape as a tuple (y, x). |
required |
xy_min |
tuple[int, int]
|
Tuple containing the origin of the image [x0, y0]. |
[0, 0]
|
Returns:
Type | Description |
---|---|
ndarray
|
The mask array. |