FormaLeaf


FormaLeaf is a software interface for exploring leaf morphology with type of formal grammar called L-systems. It was, in part, intended to be an 'idealizing machine.' Real leaf goes in, fake leaf comes out. The input is an image of a scanned leaf. The output is a formally defined, developmentally-rewindable leaf surface model. A good representation would have a similar vein branching structure and shape as the input leaf.

FormaLeaf basically works, but it can't really get good-looking matches of a given input leaf without human assistance as the automated form search process (including fitness evaluation) remains underdeveloped. Varying forms are generated by changing parameters within three structural templates: Pinnate, Palmate, and PinLobed.

A key question driving the software's development (and perhaps a plant's, too) is how a leaf's internal venation pattern relates to its external shape. The geometry of these polygonal L-systems is such that the vein lines serve as a framework for the polygon, with vertices being dropped by the turtle at the ends of these lines.



Click for project poster, project write-up.

FormaLeaf was part of a larger project called "Branching Boogaloo: Botanical Adventures in Multi-Mediated Morphologies." The full write-up for Branching Boogaloo officially lives at the Bard Digital Commons, but I have rehosted it here as well. I would only recommend reading it if you too are interested in leaves. Some sections were assembled rather clumsily so there are odd bits throughout—not to mention outright errors. The important stuff about the program itself is presented on this page, so one needn't wade through my weird bachelor's thesis to get the picture.

The leaf featured on the title page of the write-up belongs to some sort of leather-leaf viburnum (probably Viburnum rhytidophyllum), native to Asia and used as ornament in the United States.

I found this project compelling because it combined computer graphics, computer vision, formal languages, and the natural world.

Input Leaves

Some plants were harmed in the making of this project. The leaves used as input were collected from trees and other plants around Bard's campus, where there is more foliage than you can shake a stick at.


Sources include dogwood, maple, oak, hydrangea, viburnum, catalpa, tulip tree, sweetgum, sycamore, and more.

A leaf is easy to feed to a computer because it is flat. Hence, like a leaf of paper (a.k.a. a folio), a leaf from a tree can be put inside a scanner.


FEED ME

In my more unreasonable moments I ask myself whether passing a severed organ of a living being into an input-hungry, impersonal machine is in some way a destructive, unfeeling appropriation (and imposition upon the agency) of a vital, feeling natural world. I respond to myself by pointing out that a machine which eats leaves must be a vegetarian. Computers are more often chewing on the personal information and identities of human beings, which once digested apparently turn into money. Even though I had to physically damage several dozen organisms to obtain the input, I think for a computational system FormaLeaf is relatively benign.

Scanned Leaf Images


Click for scanned leaf images.

The scanned leaf images at the link above are rather pretty at full resolution; click on a leaf for full size. When viewed all together on that page, the relative sizes of the leaves are not true to life—in many cases the smaller the leaf, the larger it looks there since the big leaves have bigger images which are scaled down for display.

Download the scanned leaf images: scannedLeaves.zip

L-systems

L-systems are parallel string re-writing systems. A re-writing system is a set of rules for how symbols can be transformed into other symbols. A string is a sequence of characters. L-systems are usually re-writing strings, although there's nothing stopping them from re-writing graphs or whatever else. A re-writing system which works in parallel means that the possible transformational rules (as defined in the system) are ALL applied at every time step. This is in contrast to other kinds of formal grammars which pick a single rule to use at each time step.

L-systems can be used to construct all sorts of things that *don't* look like leaves:


In order to model leaves, FormaLeaf uses the Logo-Turtle graphical interpretation of L-systems with the "framework method" of modeling polygons. That's several levels of arbitrary abstraction, so there's not much reason to suspect that this particular method of generating nice images of leaf-like structures bears much relation to how leaves actually develop. However, there are still real biological reasons why L-systems are suited for certain flavors of plant modeling—plants exhibit repetitive modular development well imitated by recursive rules.

Output Leaves

FormaLeaf can generate random leaf models based off of three venation/lobation templates. Variety within each template is achieved through different parameters for the growth rates, lengths, and angles of the leaf veins.

There are countless existing leaf shapes FormaLeaf can't handle properly, but the variety of forms which can be generated by modifying the parameters of just these three templates is reasonably extensive.

1001 Randomly Generated Leaves


Click for randomly generated leaves.

One interesting thing about the three templates is that the two more complicated templates use the simpler Pinnate template in their own construction. Hence, they are leaf models built using leaf models.

The Pinnate template itself is a parametric modification of an L-system grammar given by Prusinkiewicz and Lindenmayer in The Algorithmic Beauty of Plants. The Palmate template uses the Pinnate template as lobes. The PinLobed template uses a modified Pinnate template for both lobes and (in some capacity) the larger structure.

Obviously nature's process is a bajillion times more complicated, but the basic idea of the development and form of an organ/organism being defined by parseable code is an important aspect of L-system plant models. In this analogy, the L-system grammar is like a genotype while the resulting visual model produced by the Turtle interpretation of the generated symbol strings is like a phenotype.

Pinnate Template

The structure of the Pinnate template comes from an L-system grammar given on page 124 of The Algorithmic Beauty of Plants. The number of iterations and parameter ranges were modified to get the kinds of forms the Pinnate template generates.

Palmate Template

The interesting thing about the Palmate template is that each lobe is literally made out of a Pinnate template. If you compare the P(t) production in both L-systems, they are doing the same thing. In the Palmate template, these individual 'lobelets' are arranged such that they emanate from the base at varying angles. It makes me wonder if in some plants, lobed palmate leaves would be compound palmate leaves (with individual 'leaflets', such as horse chestnut) if they were initiated at slightly different positions and didn't fuse early on.

PinLobed Template

Again the basic Pinnate template rule is reused for the lobes of the PinLobed template. This L-system also has an additional level of complexity, as it parameterizes lobe number as well using some conditional productions.

The PinLobed leaves also sometimes end up looking like cute little 2D plants themselves!

Development and Evolution


"Ontogeny"

Because it is a set of rules for transforming a string over the course of successive iterations, the idea of "development" is baked into the workings of an L-system. When applied to plant models, we can end up with images of growth and ontogenetic development.


Morphogenesis of the three leaf templates

"Phylogeny"

When we modify the parameters of the L-system, aspects of the mature leaf shape change. We can imagine this as operating something like evolutionary/genetic change, as this is a modification of the program which creates the leaf itself and not the execution of that program (as above).


Primary Vein Growth Rate (RP), Lateral Vein Growth Rate (RL), and Lateral Vein Angle (AN)


Primary Vein Growth Rate (RP), Primary Vein Angle (ANN), Lateral Vein Growth Rate (RL), and Lateral Vein Angle (AN)


Primary Vein Growth Rate (RP), Lateral Vein Growth Rate (RL), and Lateral Vein Angle (AN)


Tertiary Vein Growth Rate (RT), Tertiary Vein Angle (ANN), and Number of Lobe Pairs (O)



"Abiogeny"

We can have a lil' fun with this:




Interface and Functionality

Slider Mode

The interface shows an input leaf on the left, and a manipulable L-system leaf model on the right. The side panel reports measurements, labels, and a similarity score. The user can change the input leaf with number keys and the left and right arrows, and change the output template with the up and down arrows. The sliders at the bottom of the side panel change the different parameter values of the template currently in use. Unfortunately for the user, these sliders are not labeled, and not all of them even do anything for some of the templates.

Vision Mode

In Vision Mode, the user can have a look at what the visual evaluation system is seeing. The system is here making some kind of effort towards counting the number of lobes, but this functionality is, like so many others, inchoate.

Behind the scenes, the vision evaluation system does stuff. One important step is extracting the contour of the leaf. This is a simple matter of applying a binary thresholding operation.




The vision system applies a label of "Ovate", "Elliptic" or "Obovate" to the leaf shape based on the section of the leaf containing the widest part of the contour.

One of the reasons the generated images look believably like leaves is because of their color. The color for the output leaf is sampled directly from the input leaf, a bit off center so as to sample from the lamina and not the midvein.

Search Mode


A rare, cherry-picked instance where the program actually generated a decent output leaf

Search Mode doesn't really work to generate a particularly accurate model for any given input leaf—really it just generates a bunch of random candidate leaves, ranks them by fitness (how similar the candidates are to the input leaf based off a weighted combination of measured comparisons), and picks the best as the displayed match. While it isn't great at its originally intended purpose, it produces lots of cool leaf jpgs at the push of a button.


Candidate matches ranked by similarity

Future Work:

This program was never finished I don't really intend to keep working on it. However, I think there's lots of future fun to be had with plants, computer vision, and generative art.

Leaf Love

Some Further Reading: