boundary_helpers
darts_segmentation.metrics.boundary_helpers
¶
Helper functions for boundary metrics.
_boundary_arg_validation
¶
_boundary_arg_validation(
matching_threshold: float = 0.5,
matching_metric: darts_segmentation.metrics.boundary_helpers.MatchingMetric = "iou",
boundary_dilation: float | int = 0.02,
)
Source code in darts-segmentation/src/darts_segmentation/metrics/boundary_helpers.py
erode_pytorch
¶
erode_pytorch(
mask: torch.Tensor,
iterations: int = 1,
validate_args: bool = False,
) -> torch.Tensor
Erodes a binary mask using a square kernel in PyTorch.
Parameters:
-
mask
(torch.Tensor
) –The binary mask. Shape: (batch_size, height, width) or (batch_size, channels, height, width), dtype: torch.uint8
-
iterations
(int
, default:1
) –The size of the erosion. Defaults to 1.
-
validate_args
(bool
, default:False
) –Whether to validate the input arguments. Defaults to False.
Returns:
-
torch.Tensor
–torch.Tensor: The eroded mask. Shape: (batch_size, height, width), dtype: torch.uint8
Source code in darts-segmentation/src/darts_segmentation/metrics/boundary_helpers.py
get_boundary
¶
get_boundary(
binary_instances: torch.Tensor,
dilation: float | int = 0.02,
validate_args: bool = False,
)
Convert instance masks to instance boundaries.
Parameters:
-
binary_instances
(torch.Tensor
) –Target instance masks. Must be binary. Can be batched, one-hot encoded or both. (3 or 4 dimensions). The last two dimensions must be height and width.
-
dilation
(float | int
, default:0.02
) –The dilation (factor) / width of the boundary. Dilation in pixels if int, else ratio to calculate
dilation = dilation_ratio * image_diagonal
. Default: 0.02 -
validate_args
(bool
, default:False
) –Weather arguments should be validated. Defaults to False.
Returns:
-
–
tuple[torch.Tensor, torch.Tensor]: The boundaries of the instances.
Source code in darts-segmentation/src/darts_segmentation/metrics/boundary_helpers.py
instance_boundary_iou
¶
instance_boundary_iou(
instances_target_onehot: torch.Tensor,
instances_preds_onehot: torch.Tensor,
dilation: float | int = 0.02,
validate_args: bool = False,
) -> torch.Tensor
Calculate the IoU of the boundaries of instances.
Expects non-batched, one-hot encoded input from skimage.measure.label
Parameters:
-
instances_target_onehot
(torch.Tensor
) –The instance mask of the target. Shape: (num_instances, height, width), dtype: torch.uint8
-
instances_preds_onehot
(torch.Tensor
) –The instance mask of the prediction. Shape: (num_instances, height, width), dtype: torch.uint8
-
dilation
(float | int
, default:0.02
) –The dilation (factor) / width of the boundary. Dilation in pixels if int, else ratio to calculate
dilation = dilation_ratio * image_diagonal
. Default: 0.02 -
validate_args
(bool
, default:False
) –Whether to validate the input arguments. Defaults to False.
Returns: