opendvp.io.segmask_to_qupath#
- segmask_to_qupath(path_to_mask, simplify_value=1.0, save_as_detection=True)#
Convert a segmentation mask (TIFF) to QuPath-compatible detections as a GeoDataFrame or GeoJSON file.
This function loads a 2D segmentation mask image, converts it to polygons using spatialdata, and prepares the result for QuPath detection import. Optionally, it can simplify the geometry, export the detections as a GeoJSON file, and/or return the resulting GeoDataFrame.
- Parameters:
path_to_mask (str or pathlib.Path) – Path to the segmentation mask image (must be a .tif file).
simplify_value (float, default 1) – Tolerance for geometry simplification. Set to None to disable simplification.
export_path (str, optional) – If provided, writes the detections to this path as a GeoJSON file.
return_gdf (bool, default False) – If True, returns the resulting GeoDataFrame. If False, returns None.
- Returns:
The resulting GeoDataFrame if
return_gdfis True, otherwise None.- Return type:
geopandas.GeoDataFrame or None
- Raises:
ImportError – If required packages (dask, dask_image, spatialdata) are not installed.
ValueError – If input types or file extensions are incorrect.
Notes
Requires the ‘dask’, ‘dask_image’, and ‘spatialdata’ packages.
The exported GeoJSON is compatible with QuPath for detection import and visualization.