Leaf area calculation with R
Calculating the leaf area is a common task to those interested in functional ecology. To do so, ImageJ is commonly used. This program is extremely powerful, and useful. However, it requires interaction with the user, with all the associated problems (non-replicable results, too much time invested, non-automated workflows, and so on).
Calculating the leaves area is, in principle, easy: you just need to count the dark pixels, which are interpreted as leaves against a clearer background. The main problem is that we do not know the area of a pixel. In ImageJ, the user establishes manually the scale (for that reason, rules or some other reference are usually photographed along the leaves).
My script calculates the scale automatically. The idea is: a frame with sharp contrasts between dark and clear areas should be detected easily, without involvement of the user. For example, the black strips in the picture are nothing more than matrix rows (or columns) with high numerical values, close to rows (or columns) with low numerical values. Once that frame is detected, the white central cuore is easily identified. If you have leaves (and only leaves) there, and you know the white central cuore area, it is easy to calculate the leaves surface. Here is the function:
Calculating the leaves area is, in principle, easy: you just need to count the dark pixels, which are interpreted as leaves against a clearer background. The main problem is that we do not know the area of a pixel. In ImageJ, the user establishes manually the scale (for that reason, rules or some other reference are usually photographed along the leaves).
My script calculates the scale automatically. The idea is: a frame with sharp contrasts between dark and clear areas should be detected easily, without involvement of the user. For example, the black strips in the picture are nothing more than matrix rows (or columns) with high numerical values, close to rows (or columns) with low numerical values. Once that frame is detected, the white central cuore is easily identified. If you have leaves (and only leaves) there, and you know the white central cuore area, it is easy to calculate the leaves surface. Here is the function:
leafarea_function.r | |
File Size: | 6 kb |
File Type: | r |
The function has the option to trace the image processing (be careful: that option makes the code to run slowly). This is an example of how it processes the image to identify the frame and the central cuore with the leaves:
The frame was built with a white board and standard black electrical tape (total cost: 1 US$). The picture was taken by my sister with her i-Phone. And the code is free! You have no excuse to not to succeed in you leaf-area-related projects...