sopa.segmentation.stainings
sopa.segmentation.stainings.StainingSegmentation
Source code in sopa/segmentation/stainings.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
__init__(sdata, method, channels, image_key=None, min_area=0, clip_limit=0.2, clahe_kernel_size=None, gaussian_sigma=1)
Generalized staining-based segmentation
Sequential segmentation (slower)
from sopa.segmentation.stainings import StainingSegmentation
method = ... # custom callable that runs segmentation on each patch
segmentation = StainingSegmentation(sdata, method, "DAPI")
segmentation.write_patches_cells("./temp_dir")
cells = StainingSegmentation.read_patches_cells("./temp_dir")
StainingSegmentation.add_shapes(sdata, cells, image_key, "method_name")
Parallel segmentation (faster)
from sopa.segmentation.stainings import StainingSegmentation
method = ... # custom callable that runs segmentation on each patch
segmentation = StainingSegmentation(sdata, method, "DAPI")
# Run all this in a parallel manner, e.g. on different jobs
for i in range(len(sdata['sopa_patches'])):
segmentation.write_patch_cells("./temp_dir", i)
cells = StainingSegmentation.read_patches_cells("./temp_dir")
StainingSegmentation.add_shapes(sdata, cells, image_key, "method_name")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdata |
SpatialData
|
A |
required |
method |
Callable
|
A segmentation |
required |
channels |
list[str] | str
|
One or a list of channel names used for segmentation. If only one channel is provided, the image given to the |
required |
image_key |
str | None
|
Optional key of |
None
|
min_area |
float
|
Minimum area (in pixels^2) for a cell to be kept |
0
|
clip_limit |
float
|
Parameter for skimage.exposure.equalize_adapthist (applied before running cellpose) |
0.2
|
clahe_kernel_size |
int | Iterable[int] | None
|
Parameter for skimage.exposure.equalize_adapthist (applied before running cellpose) |
None
|
gaussian_sigma |
float
|
Parameter for scipy gaussian_filter (applied before running cellpose) |
1
|
Source code in sopa/segmentation/stainings.py
add_shapes(sdata, cells, image_key, shapes_key)
classmethod
Adding shapely
polygon to the SpatialData
object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdata |
SpatialData
|
A |
required |
cells |
list[Polygon]
|
List of polygons after segmentation |
required |
image_key |
str
|
Key of the image on which segmentation has been run |
required |
shapes_key |
str
|
Name to provide to the geodataframe to be created |
required |
Source code in sopa/segmentation/stainings.py
read_patches_cells(patch_dir)
classmethod
Read all patch segmentation results after running write_patch_cells
on all patches
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patch_dir |
str | list[str]
|
Directory provided when running |
required |
Returns:
Type | Description |
---|---|
list[Polygon]
|
A list of cells represented as |
Source code in sopa/segmentation/stainings.py
write_patch_cells(patch_dir, patch_index)
Run segmentation on one patch, and save the result in a dedicated directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patch_dir |
str
|
Directory inside which segmentation results will be saved |
required |
patch_index |
int
|
Index of the patch on which to run segmentation. NB: the number of patches is |
required |