darts_postprocessing
darts_postprocessing
¶
Postprocessing steps for the DARTS dataset.
binarize
¶
binarize(
probs: xarray.DataArray,
threshold: float,
min_object_size: int,
mask: xarray.DataArray,
device: typing.Literal["cuda", "cpu"] | int,
) -> xarray.DataArray
Binarize the probabilities based on a threshold and a mask.
Steps for binarization
- Dilate the mask. This will dilate the edges of holes in the mask as well as the edges of the tile.
- Binarize the probabilities based on the threshold.
- Remove objects at which overlap with either the edge of the tile or the noData mask.
- Remove small objects.
Parameters:
-
probs
(xarray.DataArray
) –Probabilities to binarize.
-
threshold
(float
) –Threshold to binarize the probabilities.
-
min_object_size
(int
) –Minimum object size to keep.
-
mask
(xarray.DataArray
) –Mask to apply to the binarized probabilities. Expects 0=negative, 1=postitive.
-
device
(typing.Literal['cuda', 'cpu'] | int
) –The device to use for removing small objects.
Returns:
Source code in darts-postprocessing/src/darts_postprocessing/postprocess.py
erode_mask
¶
erode_mask(
mask: xarray.DataArray,
size: int,
device: typing.Literal["cuda", "cpu"] | int,
edge_size: int | None = None,
) -> xarray.DataArray
Erode the mask, also set the edges to invalid.
Parameters:
-
mask
(xarray.DataArray
) –The mask to erode.
-
size
(int
) –The size of the disk to use for erosion and the edge-cropping.
-
device
(typing.Literal['cuda', 'cpu'] | int
) –The device to use for erosion.
-
edge_size
(int
, default:None
) –Define a different edge erosion width, will use size parameter if None.
Returns:
Source code in darts-postprocessing/src/darts_postprocessing/postprocess.py
prepare_export
¶
prepare_export(
tile: xarray.Dataset,
bin_threshold: float = 0.5,
mask_erosion_size: int = 10,
min_object_size: int = 32,
quality_level: int
| typing.Literal[
"high_quality", "low_quality", "none"
] = 0,
ensemble_subsets: list[str] = [],
device: typing.Literal["cuda", "cpu"]
| int = darts_postprocessing.postprocess.DEFAULT_DEVICE,
edge_erosion_size: int | None = None,
) -> xarray.Dataset
Prepare the export, e.g. binarizes the data and convert the float probabilities to uint8.
Parameters:
-
tile
(xarray.Dataset
) –Input tile from inference and / or an ensemble.
-
bin_threshold
(float
, default:0.5
) –The threshold to binarize the probabilities. Defaults to 0.5.
-
mask_erosion_size
(int
, default:10
) –The size of the disk to use for mask erosion and the edge-cropping. Defaults to 10.
-
min_object_size
(int
, default:32
) –The minimum object size to keep in pixel. Defaults to 32.
-
quality_level
(int | str
, default:0
) –The quality level to use for the mask. If a string maps to int. high_quality -> 2, low_quality=1, none=0 (apply no masking). Defaults to 0.
-
ensemble_subsets
(list[str]
, default:[]
) –The ensemble subsets to use for the binarization. Defaults to [].
-
device
(typing.Literal['cuda', 'cpu'] | int
, default:darts_postprocessing.postprocess.DEFAULT_DEVICE
) –The device to use for dilation. Defaults to "cuda" if cuda for cucim is available, else "cpu".
-
edge_erosion_size
(int
, default:None
) –If the edge-cropping should have a different witdth, than the (inner) mask erosion, set it here. Defaults to
mask_erosion_size
.
Returns: