Distributions#
Distributions are used in the Dead Leaves Model to sample object parameters such as size, aspect ratio, orientation, color, and texture. They are specified as dictionaries with the distribution type as key and its parameters as values.
Constant#
The Constant distribution returns a fixed deterministic value every time it is sampled.
Use this when you want a parameter to remain unchanged.
Use case: Fixed parameter for all leaves.
{
"constant": {
"value": <value>
}
}
Example: Constant size
Uniform (from PyTorch)#
The Uniform distribution samples values evenly from a range [low, high] (where \(a=\)low and \(b=\)high).
Use case: Random but equally likely values, e.g. random orientation or hue.
{
"uniform": {
"low": <value>,
"high": <value>
}
}
Example: Uniform size and luminance
Normal (from PyTorch)#
The Normal distribution samples values from a Gaussian (bell-shaped) distribution with mean \(\mu=\)loc and standard deviation \(\sigma=\)scale.
Use case: Gaussian noise or color.
{
"normal": {
"loc": <value>,
"scale": <value>
}
}
Example: Normal size and luminance
Beta (from PyTorch)#
The Beta distribution samples values in the range [0,1] and is controlled by two concentration parameters \(\alpha=\)concentration0 and \(\beta=\)concentration1.
Use case: Random proportions or normalized parameters, e.g. aspect ratio or blending factors.
{
"beta": {
"concentration0": <value>,
"concentration1": <value>
}
}
Example: Beta aspect ratio
Poisson (from PyTorch)#
The Poisson distribution generates integer counts based on a given rate \(\lambda\).
Use case: Polygons with random number of vertices.
{
"poisson": {
"rate": <value>
}
}
Example: Polygons with Poisson vertices number
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[8], line 11
7 "n_vertices": {"poisson": {"rate": 5}},
8 },
9 (256,256)
10 )
---> 11 leaf_table, segmentation_map = model.generate_segmentation()
12
13 colormodel = LeafAppearanceSampler(leaf_table)
14 colormodel.sample_color({"gray": {"uniform": {"low": 0.0, "high": 1.0}}})
File ~/checkouts/readthedocs.org/user_builds/deadleaves/checkouts/latest/deadleaves/deadleaves.py:335, in LeafGeometryGenerator.generate_segmentation(self)
332 continue
334 # Compute AABB, clip to canvas, query live tiles
--> 335 y_min, x_min, y_max, x_max = leaf_mask_kw[self.leaf_shape].bbox(
336 params
337 ) # pyright: ignore[reportCallIssue]
338 y_min = max(y_min, 0)
339 x_min = max(x_min, 0)
File ~/checkouts/readthedocs.org/user_builds/deadleaves/checkouts/latest/deadleaves/leaf_masks.py:304, in leaf_aabb(params, leaf_shape)
302 area = float(params["area"])
303 n_v = int(params["n_vertices"])
--> 304 r = math.sqrt(2 * area / (n_v * math.sin(2 * math.pi / n_v)))
305 return (
306 math.floor(cy - r),
307 math.floor(cx - r),
308 math.ceil(cy + r),
309 math.ceil(cx + r),
310 )
312 # Fallback — unknown shape, return infinite box (no acceleration)
ValueError: math domain error
Powerlaw#
The PowerLaw distribution is useful for heavy-tailed sizes, common in natural phenomena.
It is parameterized via a lower (low, \(x_\min\)) and an upper bound (high, \(x_\max\)) and the exponent \(k\).
For continuity with respect to \(k\) the distribution for \(k=1\) is given by
For \(k=0\) the distribution equals a uniform distribution between the lower and the upper bound.
Use case: Generating leaf sizes with many small and few large objects.
{
"powerlaw": {
"low": <value>,
"high": <value>,
"k": <value>
}
}
Example: Powerlaw size and saturation
Cosine#
The Cosine distribution produces periodic variations for values between \(-\pi\) and \(\pi\):
The frequency, \(F\) has to be an integer and specifies the number of phases on the value range.
The amplitude, \(A\) changes the intensity between 0.0 and 1.0.
Use case: Orientations of phase-like variations with periodic structure.
{
"cosine": {
"amplitude": <value>,
"frequency": <value>
}
}
Note
Random variables with this distribution always produce values between \(-\pi\) and \(\pi\) and are mainly useful to parameterized orientation distributions.
Example: Cosine orientation
Expcosine#
The ExpCosine distribution is a sharply peaked periodic distribution, useful for strongly directional parameters.
The frequency, \(F\) has to be an integer and specifies the number of periodic peaks on the value range.
The positive exponential_constant, \(c\) sets the strength of the peak.
Use case: Leaf orientations with a strong preferred direction, e.g. cardinal bias.
{
"expcosine": {
"frequency": <value>,
"exponential_constant": <value>
}
}
Note
Random variables with this distribution always produce values between \(-\pi\) and \(\pi\) and are mainly useful to parameterized orientation distributions.
Example: Exponential cosine orientation
Image#
The Image distribution samples from a set of image files in a given directory.
The class will discover all image type files in dir and uniformly sample images from the list.
Use case: Assign color or texture by sampling existing images or texture patches, respectively.
{
"image": {
"dir": <value>
}
}
Note
Sampling from this distribution will return one or multiple paths to image(s) in dir.
In particular, it will sample from all available image files in the directory provided.
Example: Color and texture from images