deadleaves.leaf_masks ===================== .. py:module:: deadleaves.leaf_masks Attributes ---------- .. autoapisummary:: deadleaves.leaf_masks.MaskFn Classes ------- .. autoapisummary:: deadleaves.leaf_masks.LeafMaskSpec Functions --------- .. autoapisummary:: deadleaves.leaf_masks.get_leaf_mask_kw deadleaves.leaf_masks.circular deadleaves.leaf_masks.rectangular deadleaves.leaf_masks.ellipsoid deadleaves.leaf_masks.polygon deadleaves.leaf_masks.leaf_aabb Module Contents --------------- .. py:data:: MaskFn Mask Function type .. py:class:: LeafMaskSpec Leaf mask data class .. py:attribute:: fn :type: MaskFn Leaf mask function, mapping shape parameters to a leaf mask. .. py:attribute:: required :type: set[str] | list[set[str]] Parameters of the leaf shape. .. py:attribute:: bbox :type: Callable[[dict[str, torch.Tensor], str], tuple[int, int, int, int]] Axis-aligned bounding box function. .. py:function:: get_leaf_mask_kw() -> dict[str, LeafMaskSpec] Return dictionary mapping leaf shapes to their mask functions and required parameters. .. py:function:: 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. .. py:function:: 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. .. py:function:: 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. .. py:function:: 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. .. py:function:: leaf_aabb(params: dict[str, torch.Tensor], leaf_shape: str) -> tuple[int, int, int, int] Compute the axis-aligned bounding box of a leaf. Args: params: Sampled leaf parameters (x_pos, y_pos, area / radius, …). leaf_shape: One of "circular", "ellipsoid", "rectangular", "polygon". Returns: (y_min, x_min, y_max, x_max) as ints, not yet clipped to canvas.