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
|
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
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|