gdf2inst
Converts a GeoDataFrame to an instance segmentation raster mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to convert to an instance segmentation mask. |
required |
xoff
|
int
|
X offset. This is used to translate the geometries in the GeoDataFrame to burn the geometries in correctly to the raster mask. |
0
|
yoff
|
int
|
Y offset. This is used to translate the geometries in the GeoDataFrame to burn the geometries in correctly to the raster mask. |
0
|
width
|
int
|
Width of the output. This should match with the underlying image width. If None, the width will be calculated from the input gdf. |
None
|
height
|
int
|
Height of the output. This should match with the underlying image height. If None, the height will be calculated from the input gdf. |
None
|
reset_index
|
bool
|
Whether to reset the index of the output GeoDataFrame. |
False
|
id_col
|
str
|
If provided, the column name to use for the instance IDs. If None, the index
of the GeoDataFrame will be used as instance IDs. Ignored if |
None
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
np.ndarray: Instance segmentation mask of the input gdf. Shape (height, width). |
Examples:
>>> from histolytics.data import hgsc_cancer_nuclei
>>> from histolytics.utils.raster import gdf2inst
>>> from skimage.measure import label
>>> from skimage.color import label2rgb
>>> import matplotlib.pyplot as plt
>>>
>>> nuc = hgsc_cancer_nuclei()
>>> # Convert the GeoDataFrame to an instance segmentation raster
>>> nuc_raster = gdf2inst(nuc, xoff=0, yoff=0, width=1500, height=1500)
>>> # Visualize the instance segmentation raster and the GeoDataFrame
>>> fig, ax = plt.subplots(1, 2, figsize=(8, 4))
>>> ax[0].imshow(label2rgb(label(nuc_raster), bg_label=0))
>>> ax[0].set_axis_off()
>>> nuc.plot(column="class_name", ax=ax[1])
>>> ax[1].set_axis_off()
>>> fig.tight_layout()
Source code in src/histolytics/utils/raster.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|