Using AI to see the wood for the trees

Researchers here have released 'GreenLens', a free app that uses AI to measure the diameter of tree trunks. It works with a high degree of accuracy – yet runs on a cheap, second-hand Android phone.
The GreenLens app is aimed at anyone with an interest in protecting and restoring forests, from governments and NGOs to landowners and environmental scientists. It was developed by researchers here in the Department of Computer Science and Technology.
The GreenLens app was originally intended for use by ecologists monitoring reforestation efforts in East Africa where high-end smartphones are unaffordable and access to the internet is patchy. (The app can function without the internet as all computing is local and all files are saved onto the device itself.) The aim was to help users gather data on reforestation so that they could assess their eligibility for carbon credits.
But enthusiasm for the app has been gathering pace since the paper ‘An app for tree trunk diameter estimation from coarse optical depth maps’ was recently published in the journal Ecological Informatics.
The researchers behind GreenLens have now had interest from countries including Brazil, Romania, Scotland, Tanzania and Vietnam.

The researchers behind GreenLens have now had interest from countries including Brazil, Romania, Scotland, Tanzania and Vietnam.
The researchers behind GreenLens have now had interest from countries including Brazil, Romania, Scotland, Tanzania and Vietnam.
Described as 'an intuitive app for accelerating forest inventory mapping', the open source GreenLens app can be downloaded from GitHub, along with an installation tutorial and a manual. And first year PhD student Zhengpeng (Frank) Feng (left), one of the research team, is currently working on a version for the iPhone that he hopes will become available next year.
"Other apps for measuring forest plots – sample areas of woodland – are available," says Frank’s supervisor, Srinivasan Keshav, Robert Sansom Professor of Computer Science. "But those for Android phones tend not to perform as well as ours, while those designed for the iPhone require the purchase of a high-end phone that is not affordable for researchers in the Global South.
"We believe ours is the only app to sit in the 'sweet spot' of offering high quality for low cost."
The ability quickly and accurately to measure forest plots has become an important tool in efforts to combat the climate crisis. Restoring degraded or destroyed areas of forest is vital to addressing the twin challenges of storing carbon dioxide, as growing trees do, and combatting biodiversity loss.
And money from government for carbon credit schemes can be directed to reforestation schemes if they can be properly validated, for example by measuring and mapping the growth and state of replanted trees. But to date, many forest plots are still measured by field scientists or volunteers going into the woods and manually wrapping a tape measure around each tree’s trunk – a process that is time-consuming and not always completely accurate.

"When measuring trees manually," Keshav says, "you find that one person might slightly under-estimate a tree's diameter, whereas another might slightly over-estimate. Moreover, measuring tree trunks with thorny bushes around them is a scratchy affair!"
And this is where forest measurement apps come in. Other members of Keshav’s research team have previously produced phone-based technology for measuring forests. PhD student Amelia Holcomb developed an algorithm that uses computer vision techniques to accurately measure trees almost five times faster than traditional, manual methods. The algorithm used low-resolution LiDAR (light detection and ranging) sensors that are incorporated into mobile phones.
But unfortunately, these sensors tend to be found only in high-end phones which puts them beyond the financial reach of many landowners, ecologists and scientists working in the global south. "So we were asked if we could develop something better," says Keshav.
The goal was to find alternative solutions for taking tree measurements such as trunk Diameter at Breast Height (DBH) without using depth sensors.


"DBH is a vital sign of a tree's size, growth and biomass," Frank explains. "The bigger a tree is, the older it is and therefore the more carbon it is sequestering."
Forest scientists have developed allometric equations that convert DBH measurements into accurate measurements of trees' biomass and carbon stocks. But even with an app, automating the measurements of DBH is not always easy.
This is because many trees do not grow up entirely straight, with knots and burls. Or they may stand in undergrowth with branches, leaves and bushes obscuring the phone camera’s view of the trunk, making it difficult for the depth sensors to accurately assess the measurement of the trunk. So Frank set about looking for ways to get these measurements without using depth sensors.
He knew that to predict a tree trunk’s diameter, two parameters are needed: the trunk’s width in the photo, and the distance from the phone to the centre of the trunk when the picture was taken. "With these two parameters, we can calculate the real width of the trunk using trigonometry."

Depth sensors can easily capture the distance from the phone to the trunk by emitting a laser and then receives it back but Frank was trying to capture the information without using such sensors. So he turned to Google ARCore. This is an Augmented Reality toolkit that helps users estimate the distance to an object through an algorithm called structure-from-motion or depth-from-motion.
"As the user moves the phone in front of an object," Frank explains, "it creates an image – called a depth map – where each pixel represents the distance to that object. And with this, we can use to determine the distance to the trunk. The depth map is not as accurate as using a dedicated depth sensor, but we can still use it."
Frank then worked on developing AI methods of using the information from both the depth map and an ordinary photo of the tree to determine the trunk of the width and therefore its diameter. And he was successful.
The app uses a four-stage image processing algorithm to refine the boundaries of the tree in the image so it can estimate the width of the trunk accurately. Then an AI model (a Deep Neural Network) works on the depth maps to derive accurate information from them, even though the maps are fairly low quality.

"What’s really impressive about Frank’s work is that he has used AI to create a model that can measure the DBH of a tree even when that image is of poor quality – for example, it’s blurry or low resolution," Keshav says. "This is a major advance."
As the paper highlights, this app makes a sophisticated tree measurement tool – that is comparable with current high-cost tools available – on an entry-level smartphone.
The researchers stress that the app's development was collaborative and also involved Miranda Xie. An undergraduate research assistant at the University of Waterloo, she worked on the core app, especially its front end, with Keshav.
Another major advance, according to the paper, is that using the GreenLens app speeds up data collection, making diameter measurement up to five times faster than it would be using traditional manual surveying.
"There are so many forest and environmental scientists and landowners who could use this tool," Keshav says. "We are really excited to make it available to them."
- The open source GreenLens app can be downloaded from GitHub, along with an installation tutorial and a manual. It's hoped that a version for iPhone will become available next year.
