inst2gdf
Convert an instance segmentation raster mask to a GeoDataFrame.
Note
This function should be applied to nuclei instance segmentation masks. Nuclei
types can be provided with the type_map
and class_dict
arguments if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inst_map
|
ndarray
|
An instance segmentation mask. Shape (H, W). |
required |
type_map
|
ndarray
|
A type segmentation mask. Shape (H, W). If provided, the types will be included in the resulting GeoDataFrame in column 'class_name'. |
None
|
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], default=None
|
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. |
gaussian_smooth
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: A GeoDataFrame of the raster instance mask. Contains columns:
|
Examples:
>>> from histolytics.utils.raster import inst2gdf
>>> from histolytics.data import hgsc_cancer_inst_mask, hgsc_cancer_type_mask
>>> # load raster masks
>>> inst_mask = hgsc_cancer_inst_mask()
>>> type_mask = hgsc_cancer_type_mask()
>>> # convert to GeoDataFrame
>>> gdf = inst2gdf(inst_mask, type_mask)
>>> print(gdf.head(3))
id class_name geometry
0 135 1 POLYGON ((405.019 0.45, 405.43 1.58, 406.589 2...
1 200 1 POLYGON ((817.01 0.225, 817.215 0.804, 817.795...
2 0 1 POLYGON ((1394.01 0.45, 1394.215 1.58, 1394.79...
Source code in src/histolytics/utils/raster.py
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 |
|