sem2gdf
Convert an semantic segmentation raster mask to a GeoDataFrame.
Note
This function should be applied to semantic tissue segmentation masks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sem_map
|
ndarray
|
A semantic segmentation mask. Shape (H, W). |
required |
xoff
|
int
|
The x offset. Optional. The offset is used to translate the geometries in the GeoDataFrame. If None, no translation is applied. |
None
|
yoff
|
int
|
The y offset. Optional. The offset is used to translate the geometries in the GeoDataFrame. If None, no translation is applied. |
None
|
class_dict
|
Dict[int, str]
|
A dictionary mapping class indices to class names. e.g. {1: 'neoplastic', 2: 'immune'}. If None, the class indices will be used. |
None
|
min_size
|
int
|
The minimum size (in pixels) of the polygons to include in the GeoDataFrame. |
15
|
smooth_func
|
Callable
|
A function to smooth the polygons. The function should take a shapely Polygon
as input and return a shapely Polygon. Defaults to |
uniform_smooth
|
returns: gpd.GeoDataFrame: A GeoDataFrame of the raster semantic mask. Contains columns:
- 'id' - the numeric pixel value of the semantic mask,
- 'class_name' - the name of the class (same as id if class_dict is None),
- 'geometry' - the geometry of the polygon.
Examples:
>>> from histolytics.utils.raster import sem2gdf
>>> from histolytics.data import hgsc_cancer_type_mask
>>> # load semantic mask
>>> type_mask = hgsc_cancer_type_mask()
>>> # convert to GeoDataFrame
>>> gdf = sem2gdf(type_mask)
>>> print(gdf.head(3))
uid class_name geometry
0 2 2 POLYGON ((850.019 0.45, 850.431 1.58, 851.657 ...
1 2 2 POLYGON ((1194.01 0.225, 1194.215 0.795, 1194....
2 1 1 POLYGON ((405.019 0.45, 405.43 1.58, 406.589 2...
Source code in src/histolytics/utils/raster.py
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 |
|