deadleaves.leaf_masks#
Attributes#
Mask Function type |
Classes#
Leaf mask data class |
Functions#
|
Return dictionary mapping leaf shapes to their mask functions |
|
Validate parameters for a circular shape and return a canonical dict. |
|
Generate mask of circle from given area and x-y-position on tensor. |
|
Axis-aligned bounding box for a circle. |
|
Validate parameters for a rectangular shape and return a canonical dict. |
|
Generate mask of rectangle from given area, aspect ratio, orientation, |
|
Axis-aligned bounding box for a rectangle. |
|
Validate parameters for a ellipsoidal shape and return a canonical dict. |
|
Generate mask of ellipsoid from given area, aspect ratio, orientation, |
|
Axis-aligned bounding box for a ellipsoid. |
|
Validate parameters for a polygon shape and return a canonical dict. |
|
Generate mask of regular polygon from given area, number of vertices |
|
Axis-aligned bounding box for a polygon. |
Module Contents#
- deadleaves.leaf_masks.MaskFn#
Mask Function type
- class deadleaves.leaf_masks.LeafMaskSpec#
Leaf mask data class
- required: set[str] | list[set[str]]#
Parameters of the leaf shape.
- bbox: Callable[[dict[str, torch.Tensor]], tuple[int, int, int, int]]#
Axis-aligned bounding box function.
- deadleaves.leaf_masks.get_leaf_mask_kw() dict[str, LeafMaskSpec]#
Return dictionary mapping leaf shapes to their mask functions and required parameters.
- deadleaves.leaf_masks.circular_validated_params(params: dict[str, torch.Tensor] | pandas.Series) dict#
Validate parameters for a circular shape and return a canonical dict.
- Args:
- params (dict[str, torch.Tensor] | pd.Series):
Circle parameter values.
- Raises:
- ValueError:
Neither radius nor area or both are provided.
- ValueError:
Area or radius is negative.
- Returns:
- dict:
Canonical dict for circle parameter values.
- deadleaves.leaf_masks.circular(index_grid: tuple[torch.Tensor, torch.Tensor], params: dict[str, torch.Tensor] | pandas.Series) torch.Tensor#
Generate mask of circle from given area and x-y-position on tensor.
- Args:
- index_grid (tuple[tensor, tensor]):
x and y indices of area to be masked.
- params (dict[str, tensor]):
Value for each parameter.
- Returns:
- torch.Tensor:
Leaf mask.
- deadleaves.leaf_masks.circular_aabb(params: dict[str, torch.Tensor] | pandas.Series) tuple[int, int, int, int]#
Axis-aligned bounding box for a circle.
- Args:
- params (dict[str, torch.Tensor] | pd.Series):
Circle parameter values.
- Returns:
- tuple[int, int, int, int]:
(y_min, x_min, y_max, x_max) as ints, not yet clipped to canvas.
- deadleaves.leaf_masks.rectangular_validated_params(params: dict[str, torch.Tensor] | pandas.Series) dict#
Validate parameters for a rectangular shape and return a canonical dict.
- Args:
- params (dict[str, torch.Tensor] | pd.Series):
Rectangle parameter values.
- Raises:
- ValueError:
Area is negative.
- ValueError:
Aspect ratio is non-positive.
- Returns:
- dict:
Canonical dict for rectangle parameter values.
- deadleaves.leaf_masks.rectangular(index_grid: tuple[torch.Tensor, torch.Tensor], params: dict[str, torch.Tensor] | pandas.Series) torch.Tensor#
Generate mask of rectangle from given area, aspect ratio, orientation, and x-y-position on tensor.
- Args:
- index_grid (tuple[tensor, tensor]):
x and y indices of area to be masked.
- params (dict[str, tensor]):
Value for each parameter.
- Returns:
- torch.Tensor:
Leaf mask.
- deadleaves.leaf_masks.rectangular_aabb(params: dict[str, torch.Tensor] | pandas.Series) tuple[int, int, int, int]#
Axis-aligned bounding box for a rectangle.
- Args:
- params (dict[str, torch.Tensor] | pd.Series):
Rectangle parameter values.
- Returns:
- tuple[int, int, int, int]:
(y_min, x_min, y_max, x_max) as ints, not yet clipped to canvas.
- deadleaves.leaf_masks.ellipsoid_validated_params(params: dict[str, torch.Tensor] | pandas.Series) dict#
Validate parameters for a ellipsoidal shape and return a canonical dict.
- Args:
- params (dict[str, torch.Tensor] | pd.Series):
Ellipsoid parameter values.
- Raises:
- ValueError:
Area is negative.
- ValueError:
Aspect ratio is non-positive.
- Returns:
- dict:
Canonical dict for ellipsoid parameter values.
- deadleaves.leaf_masks.ellipsoid(index_grid: tuple[torch.Tensor, torch.Tensor], params: dict[str, torch.Tensor] | pandas.Series) torch.Tensor#
Generate mask of ellipsoid from given area, aspect ratio, orientation, and x-y-position on tensor.
- Args:
- index_grid (tuple[tensor, tensor]):
x and y indices of area to be masked.
- params (dict[str, tensor]):
Value for each parameter.
- Returns:
- torch.Tensor:
Leaf mask.
- deadleaves.leaf_masks.ellipsoid_aabb(params: dict[str, torch.Tensor] | pandas.Series) tuple[int, int, int, int]#
Axis-aligned bounding box for a ellipsoid.
- Args:
- params (dict[str, torch.Tensor] | pd.Series):
Ellipsoid parameter values.
- Returns:
- tuple[int, int, int, int]:
(y_min, x_min, y_max, x_max) as ints, not yet clipped to canvas.
- deadleaves.leaf_masks.polygon_validated_params(params: dict[str, torch.Tensor] | pandas.Series) dict#
Validate parameters for a polygon shape and return a canonical dict.
- Args:
- params (dict[str, torch.Tensor] | pd.Series):
Polygon parameter values.
- Raises:
- ValueError:
Area is negative.
- ValueError:
Number of vertices is smaller than 3.
- ValueError:
Number of vertices is non-integer.
- Returns:
- dict:
Canonical dict for polygon parameter values.
- deadleaves.leaf_masks.polygon(index_grid: tuple[torch.Tensor, torch.Tensor], params: dict[str, torch.Tensor] | pandas.Series) torch.Tensor#
Generate mask of regular polygon from given area, number of vertices and x-y-position on tensor.
- Args:
- index_grid (tuple[tensor, tensor]):
x and y indices of area to be masked.
- params (dict[str, tensor]):
Value for each parameter.
- Returns:
- torch.Tensor:
Leaf mask.
- deadleaves.leaf_masks.polygon_aabb(params: dict[str, torch.Tensor] | pandas.Series) tuple[int, int, int, int]#
Axis-aligned bounding box for a polygon.
- Args:
- params (dict[str, torch.Tensor] | pd.Series):
Polygon parameter values.
- Returns:
- tuple[int, int, int, int]:
(y_min, x_min, y_max, x_max) as ints, not yet clipped to canvas.