Partial sampling#

The Dead Leaves Model allows controlling how many leaves are sampled and where they appear.

Sparse sampling#

Specifying the argument n_sample in the LeafGeometryGenerator limits the number of leaves to sample. If the sampling stops before the entire image is filled, the resulting segmentation will contain empty pixels.

Example

Hide code cell source

from deadleaves import LeafGeometryGenerator, LeafAppearanceSampler, ImageRenderer
import torch

model = LeafGeometryGenerator(
    "circular", 
    {"area": {"powerlaw": {"low": 100.0, "high": 10000.0, "k": 1.5}}},
    (512,512),
    n_sample = 150
)
leaf_table, segmentation_map = model.generate_segmentation()

colormodel = LeafAppearanceSampler(leaf_table)
colormodel.sample_color({"gray": {"uniform": {"low": 0.0, "high": 1.0}}})

renderer = ImageRenderer(colormodel.leaf_table, segmentation_map)
renderer.render_image()
renderer.show(figsize = (3,3))
../_images/ebf5abf32694dc264e8700f0f3435918967b639d65a49c6385c94cfce097c2d6.png

Masking#

Passing a position_mask to the LeafGeometryGenerator will exclude masked positions from the sampling process. Any pixel where sampling is prohibited may remain empty in the segmentation.

The position mask may be passed as a boolean numpy array or torch tensor. Alternatively, a dictionary can be passed which contains a shape key to select a leaf mask shape and a params key specifying the parameters for the respective shape of leaf mask.

Example

Hide code cell source

from deadleaves import LeafGeometryGenerator, LeafAppearanceSampler, ImageRenderer

model = LeafGeometryGenerator(
    "circular", 
    {"area": {"powerlaw": {"low": 100.0, "high": 10000.0, "k": 1.5}}},
    (512,512),
    position_mask = {
        "shape": "circular",
        "params": {"area": 512*512*0.4}
    }
)
leaf_table, segmentation_map = model.generate_segmentation()

colormodel = LeafAppearanceSampler(leaf_table)
colormodel.sample_color({"gray": {"uniform": {"low": 0.0, "high": 1.0}}})

renderer = ImageRenderer(colormodel.leaf_table, segmentation_map)
renderer.render_image()
renderer.show(figsize = (3,3))
../_images/9ba0bf20ffa1ab66d60cf3a03d7e46efe9423a8a2601f627c5ae78d26bec5cf9.png

Background color#

Empty pixels resulting from sparse sampling or masked positions are filled with a RGB background color. The background color can be specified explicitly via the ImageRenderer argument background_color, if not specified the background will be black.

Example

Hide code cell source

from deadleaves import LeafGeometryGenerator, LeafAppearanceSampler, ImageRenderer
import torch

model = LeafGeometryGenerator(
    "circular", 
    {"area": {"powerlaw": {"low": 100.0, "high": 10000.0, "k": 1.5}}},
    (512,512),
    n_sample = 150
)
leaf_table, segmentation_map = model.generate_segmentation()

colormodel = LeafAppearanceSampler(leaf_table)
colormodel.sample_color({"gray": {"uniform": {"low": 0.0, "high": 1.0}}})

renderer = ImageRenderer(colormodel.leaf_table, segmentation_map, background_color=torch.tensor([0.1,0.5,0.1]))
renderer.render_image()
renderer.show(figsize = (3,3))
../_images/9a74d05b9e248dd9b8370419e5568168b832e0230974fb6a5520e2363d0dfa70.png