fiber_feats
Extract collagen fiber features from an H&E image.
Note
This function extracts collagen fibers from the image and computes various metrics on the extracted fibers. Allowed metrics are:
- tortuosity
- average_turning_angle
- length
- major_axis_len
- minor_axis_len
- major_axis_angle
- minor_axis_angle
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input H&E image. Shape (H, W, 3). |
required |
metrics
|
Tuple[str]
|
The metrics to compute. Options are: - "tortuosity" - "average_turning_angle" - "length" - "major_axis_len" - "minor_axis_len" - "major_axis_angle" - "minor_axis_angle" |
required |
label
|
ndarray
|
The nuclei binary or label mask. Shape (H, W). This is used to mask out the nuclei when extracting collagen fibers. If None, the entire image is used. |
None
|
mask
|
ndarray
|
Binary mask to restrict the region of interest. Shape (H, W). For example, it can be used to mask out tissues that are not of interest. |
None
|
normalize
|
bool
|
Flag whether to column (quantile) normalize the computed metrics or not. |
False
|
rm_bg
|
bool
|
Whether to remove the background component from the edges. |
False
|
rm_fg
|
bool
|
Whether to remove the foreground component from the edges. |
False
|
device
|
str
|
Device to use for collagen extraction. Options are 'cpu' or 'cuda'. If set to 'cuda', CuPy and cucim will be used for GPU acceleration. This affects only the collagen extraction step, not the metric computation. |
'cpu'
|
num_processes
|
int
|
The number of processes when converting to GeoDataFrame. If -1, all available processes will be used. Default is 1. Ignored if return_edges is False. |
1
|
reset_uid
|
bool
|
Whether to reset the UID of the extracted fibers. Default is True. If False, the original UIDs will be preserved. |
required |
return_edges
|
bool
|
Whether to return the extracted edges as a GeoDataFrame. Default is False. |
False
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: A GeoDataFrame containing the extracted collagen fibers as LineString geometries and the computed metrics as columns. |
Examples:
>>> from histolytics.data import hgsc_stroma_he, hgsc_stroma_nuclei
>>> from histolytics.utils.raster import gdf2inst
>>>
>>> # Load example image and nuclei annotation
>>> img = hgsc_stroma_he()
>>> label = gdf2inst(hgsc_stroma_nuclei(), width=1500, height=1500)
>>>
>>> # Extract fiber features
>>> edge_gdf = fiber_feats(
... img,
... label=label,
... metrics=("length", "tortuosity", "average_turning_angle"),
... device="cpu",
... num_processes=4,
... normalize=True,
... return_edges=True,
... )
>>> print(edge_gdf.head(3))
uid class_name geometry 0 1 1 LINESTRING (29.06525 26.95506, 29.03764 26.844...
1 2 1 MULTILINESTRING ((69.19964 89.83999, 69.01369 ...
2 3 1 MULTILINESTRING ((51.54728 1.36606, 51.67797 1...
length tortuosity average_turning_angle
0 0.450252 0.372026 0.294881
1 0.977289 0.643115 0.605263
2 0.700793 0.661500 0.560562
Source code in src/histolytics/stroma_feats/collagen.py
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 205 206 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 |
|