USPLeaf : Automatic leaf area determination using a computer vision system 1 USPLeaf : Determinação automática da área foliar usando visão computacional

Computer vision systems based on digital image processing have been proposed as alternative tools to traditional methods to estimate leaf area, replacing the most time-consuming steps and laboring manual measurements. However, many of the available applications are still based on manual determination of leaf dimensions or require excessive and laborious user interventions before providing results. USPLeaf was designed to process images containing single or multiple leaves, and automatically determine the leaf area without user intervention. The accuracy for leaf area measurements of the software was compared to the results obtained by the standard method, an electronic planimeter (LI-3100). The vegetal species, Mavuno grass (MAV, Urochloa hybrid) and Macrotyloma axillare (MAC), were chosen because they are characterized by different leaf shapes. A smartphone camera was used as image capture device. When using a standard black paper square of 9 cm2, both LI3100 and USPLeaf provided accurate and precise results, with an estimated average area of 8.90 and 9.00 cm2 and a standard deviation of 0.17% and 0.00%, respectively. The relative error rate for the vegetal species varied from -6.37 to 2.25%. The regression analysis indicated that the software was a precise tool to estimate leaf area (R2=0.983 for MAV and 0.977 for MAC), but it also revealed that samples inferior to 25 cm2 for grasses and 15 cm2 for legume species should be avoided. The software can be used as an automated tool in image processing aiming to determine leaf area from digital images.


INTRODUCTION
The extraordinary development of resources in electronics and informatics (GOMES; LETA, 2012) and the evolution of technology sensors integrated to machine and computer vision systems for agriculture applications have led to the establishment of new techniques of measurement of plant traits (VARMA; OSURI, 2013), growth monitoring, weeds or plant diseases detection (PARTEL; KAKARLA; AMPATZIDIS, 2019), and are also being successfully applied for pasture nutritional diagnosis (MUTANGA; SKIDMORE; VAN WIEREN, 2003) in pastured-based systems and crop production, increasing productivity at the same time it allows to minimize negative environmental impacts.
Studies on plant development, frequently, depend on measurements of leaf dimension, since the leaf area and their related parameters (specific leaf area, net assimilation rate, leaf area ratio and leaf area index), can be considered the plant traits of most impact on growth, photosynthetic and transpiration process (VARMA; OSURI, 2013), as well as they can be used to monitor and detect natural variation and mutation on plant population (MILLER; PARKS;SPALDING, 2007). In many of these applications, a minimum data set (from 200 up to 4000 leaves) has been measured for generating accurate models for estimating the leaf area and its related parameters (CARGNELUTTI FILHO et al., 2012, 2015. Thus, the development of computer vision systems that could replace the most timeconsuming and laboring manual measurements to estimate the leaf area would greatly benefit the research on plant development (MILLER;PARKS;SPALDING, 2007).
Software for digital image processing have been proposed as an alternative tool to the traditional methods of leaf area determination, but many of the available applications are still entirely based on manual measurements of leaf length and width (CARVALHO et al., 2017) or require excessive user interventions into the software to obtain the results (VARMA; OSURI, 2013). For example, Datta and Chakroboarty (2018) reported a method for estimation of leaf area of single leaves, using a pixel counting method in the Adobe Photoshop and a desktop scanner to acquire images. However, essential steps of image processing, such as background removal and settings for image thresholding, were based on manual procedures, requiring a minimum user training and knowledge on image analysis. Besides, the applicability for field measurements is limited by the availability of electric power the scanner requires.
Thus, desirable qualities in the new computer vision tools for leaf area determination include high accuracy, a high degree of automation (MILLER;PARKS;SPALDING, 2007), with minimum user intervention, besides being fast and of low cost (VARMA; OSURI, 2013). Moreover, it would be of great interest if the software were able to process images acquired from different devices of image capture, allowing practicality for outdoor measurements. Based on this background, USPLeaf is a free software, designed to process images containing single or multiple leaves, as well as to determine automatically the leaf area from one or more images composing a given sample without user intervention.
Devices used for image capture can be desktop scanners, commercial cameras, smartphones or tablets, thus ensuring no dependence on electric power and enabling real time field measurements. This paper reports the accuracy for leaf area measurement of USPLeaf, using a smartphone as image capture device, by comparing the results with the standard method, using an electronic planimeter.

MATERIAL AND METHODS
The field experiment was carried out at the Laboratory of Technology and Information Systems (LTSI) of the Faculty of Animal Science and Food Engineering (FZEA), University of São Paulo (USP), Pirassununga, SP, Brazil (21°36′ N, 47°15′ W, 620 m a.s.l.). The plant species chosen to test the accuracy of the software measurements were obtained in the experimental area of the Study Group of Forage Plants and Pastures (GEFEP), and consisted of Mavuno grass (Urochloa hybrid), a tropical perennial grass with long, hairy and narrow leaf blades with parallel veins and tapering to a pointed tip; and Macrotyloma axillare, a tropical perennial legume with alternately arranged leaves, compound of three not hairy leaflets with a distinct central vein and lateral veins on each side, and obtuse to acute apices. For both species, it was selected only fully expanded leaves, with healthy and non-damaged leaf blades or leaflets, and no signs of senescence. The Mavuno grass (Urochloa hybrid) and Macrotyloma axillare were chosen because they are used as forage plant for grazing and characterized by different leaf shapes.

Images acquisition
Immediately after samples were harvest in the field, they were allocated in plastic bags and stored in a box with ice to avoid water loss and winding the leaf blades and leaflets. Leaves or leaflets were then placed on an image collecting table specifically developed for this purpose, in which all images were acquired and, then, were again maintained in the box with ice. The estimated time among the sampling and the beginning of USPLeaf: Automatic leaf area determination using a computer vision system the procedures for images acquisition was approximately 10 minutes.
The table was constructed with an opaque white background, and a useful area equal to an A4 sheet (landscape mode, 297 x 210 mm). A movable cover of anti-glare glass with 3 mm of thickness was inserted aiming at fixing and flattening the samples, avoiding possible folds and minimizing shadows. In the upper left corner of the useful area a black square of 1 cm x 1 cm (1 cm²) was inserted, which is used by the software as a known area for the scale calibration. An inverted 'L' shape fixed support with a retractable rod, which allows adjustments on the height of the device used for image capture, was positioned on the right side of the image collecting table.
The device used for images capture was a back camera of a smartphone Samsung Galaxy A10 with 13-megapixel resolution, at a height of 23 cm aiming to provide a full coverage of the useful area for image capture. In this acquisition step, the image must have a resolution equal to or greater than 96 dpi, thus ensuring less noise during collection. Leaf area was estimated from 15 samples, and from each sample three images were acquired; samples were composed of two leaf blades of Mavuno grass and two leaflets of Macrotyloma axillare. A total of 10 standard figures were made with black paper in a square format measuring 9 cm², and from each three images were also acquired at a height of 23 cm. All images were captured without using a flashlight in a welllighted room. The software is able to process a number of leaves higher than used in the present experiment. In a case of samples containing a greater number of leaves, the software allows the processing of two, three or more images, and the final result will be the sum of the leaf area of each image. The user only needs to upload and identify images composing the same sample into de software. However, if a sample has an area larger than an A4 sheet, it can be segmented without affecting the calculation of the leaf area. In this case, it would be a processing containing several leaf blades.

USPLeaf software
The programming language chosen for the software implementation was PhP (Hypertext Preprocessor), version 5.6, license Open Source. The PhP language was implemented in conjunction with HTML 5 (HyperText Markup Language) as well as JavaScript and CSS (Cascading Style Sheets) to relieve the server of data validation processes and HTML page formatting, respectively. For information storage, the MySql (Structured Query Language) database management system (DBMS) was used. The software was hosted on the MAPAG Research Group website (http://www. mapag.com.br/softwares/uspleaf/), with free online access.
Pre-processing, processing and results generation codes were implemented as a way for the software to work as an automated leaf area meter (Figure 1), and the only user intervention is related to images acquisition and uploading. This ensures greater accuracy on measurements, since processing is autonomous and independent of the operator subjectivity. In the pre-processing step a low pass filter (median filter) was applied, according to Eq. (1) and Eq.
(2) to remove the noise. This nonlinear filter increases impulse noise capability by keeping edge characteristics in good conditions, eliminating lines and other non-image details (ZHU; HUANG, 2012; YOUSEFI, 2011).
where: g is the output image, f is original image, (x,y) is the coordinate of the point; W is the two-dimensional mask, preferably an odd Matrix (s x s); med is the function that scans the original image f with the Matrix W, which contains the point (x, y) and its adjacent neighbors, returning after ordering the numbers the central value of the Matrix W; N is the number of elements in the odd Matrix W and is calculated by 2 * k + 1; k is a number of elements before and after the point (x, y) and s is the dimension of Matrix W that corresponds to k -1.
In the next step, the image was converted to grayscale (h) and the regions of interest (ROI), pixels with leaves information, were obtained by thresholding method (Otsu) generating a binary image, Eq. (3).
( 3) where: h is image in grayscale; I is segmented image; (x, y) is pixel position and T is threshold value obtained using Otsu method.
The best value of T is the value with the minimum variation within the class variation. The variation within the class is defined according to Eq. (4) (YOUSEFI, 2011): where: , as the weight, mean, and variance of class cb (Background) with intensity value from 0 to T, respectively and , , equal for class cf (Foreground) with intensity value from T+1 to 255; σ 2 w as the weighed sum of group variances; H(i) = is a histogram probabilities of the observed gray scale ranging from 0 to 255.
The Otsu method aims to separate classes of different objects in an image, identifying what is foreground and background, according to Eq. (3) and (4). Thus, the method scans the image transformed into a matrix with values between 0 and 255 (gray scale), applying the threshold value over the value of each pixel in the matrix, in the x and y coordinates, making the separation between the background (CB) and the foreground (CF). Therefore, the objective is to find the threshold value with the minimum entropy for the sum of CB and CF, determining the limit value of each class based on the statistical information in the image, where for a threshold value of choice T, the variation of classes CB and CF can be calculated. The value of the ideal limit is calculated by minimizing the sum of the variations of the weighed groups, where the weights are the probability of the respective classes (Eq. (4)) (YOUSEFI, 2011). After segmenting the classes, the next step is to extract the region of interest (ROI) to determine the leaf area. Once the image is binarized, the software scans the image by counting the existing black dots that correspond to the reference square, located on the limit of 1 -400 pixels horizontally and vertically of the upper left corner of the useful area of the image. Afterwards, the algorithm scans again the whole image, but now counting the black pixels corresponding to the leaves. The black pixels corresponding to the reference square will serve as the basis for determining the total sampled leaf area, according to Eq. (5). (5) where: Pf (x, y) corresponding to the black pixels referring to the leaf area in the sampled image; Pq (x, y) corresponding to the black pixels referring to the reference square area in the sampled image.
The same samples from which images were acquired and analyzed with USPLeaf were subjected to leaf area measurements using the standard method, an electronic planimeter (Li-3100, LI-COR, USA), and no form of image acquisition was required for this method. Samples were placed between the guides on the lower transparent belt, and automatically conveyed across the scanning bed. A press roller flattens any curled edges and feeds the leaves between the transparent belts. As the sample pass through the belt under the USPLeaf: Automatic leaf area determination using a computer vision system fluorescent light source of 15 W, the projected image is reflected by a system of three mirrors to a scanning camera, and the cumulative area for the group of leaves (in cm²) composing a given sample is shown on the LED display. All measurements procedures followed recommendations of the manufacturer (LI-COR ® , 1995).

Statistical analysis and comparisons between methods
The data set was analyzed as a completely randomized design, considering USPLeaf software and the standard method (the electronic planimeter) as the treatments. The leaf area data were subjected to analysis of variance using the MIXED procedure for mixed models of SAS® (Statistical Analysis System) version 9.2 for Windows®. Means of the treatments were estimated using the "LSMEANS" (Least Squares Means) command adjusted to the Tukey test, and means were declared significantly different at p < 0.01. The relative error rate (RER, %) of the estimated values of the standard figure represents the difference between the estimates by a given equipment (USPLeaf or LI-3100) and the actual values, and results are given as a percentage of the actual value (in this experiment 9 cm²). For samples of Mavuno grass and Macrotyloma axillare, the RER was calculated only for USPLeaf software (ALI et al., 2012;KAUR et al., 2014), as describe by Eq. (6): where: LAd is the leaf area estimated by the software; and LAstd is the leaf area determined by the standard method (leaf area meter, model LI-3100, LI-COR, Lincoln, Nebraska, USA).
The simple linear regression equations and their respective determination coefficients (R 2 ) were obtained with the REG procedure of SAS®. The dependent variable (Y) considered the leaf area values obtained with the SEM represents the standard error of the means; CV represents the coefficient of variation and SDev represents the standard deviation standard method, and the independent variables (X) were the leaf area estimated with USPLeaf. This statistical test was conducted following the hypotheses: H0: ᵦ0 = 0 and ᵦ1 = 1 and H1: not H0, where ᵦ0 is the intercept and ᵦ1 is the slope of the linear equation. The null hypothesis was not rejected when the predicted and observed values were similar, shown by plotting LA USPLeaf values on the X axis and LA LI3100 values on the Y axis.

RESULT AND DISCUSSION
In the present experiment, it was observed that both the standard method, using an electronic planimeter (LI-3100), and USPLeaf software provided accurate and precise results for the standard figure (Table 1), with an estimated average area of 8.90 and 9.00 cm² and a standard deviation (SDev) of 0.17% and 0.00%, respectively. For the vegetal species, the highest average leaf area and SDev were observed for Macrotyloma axillare samples. For both species, the average leaf area was higher when using the standard method (LA LI3100 ) compared with the measurements provided by USPLeaf software (LA USPLeaf ).
In a similar purpose of the present experiment, Ferreira et al. (2017) evaluated the performance of the Digital Determination of Areas (DDA) software to estimate the area of standard figures with different forms and sizes from digital images saved in monochrome bitmap file format, using a flatbed scanner (200 DPI). Authors observed that the area measurements of standard figures were subjected to greater variation when determined by the electronic planimeter than when determined by the proposed digital method. In the present experiment, the highest standard error of the mean (SEM) and Sdev for the average area of the standard figures, leaves of Mavuno grass and leaflets of Macrotyloma axillare were also observed by using the electronic planimeter. Sources of variation in leaf area measurements by using LA LI3100 during the sampling routine may include water losses, particularly if the time between the cutting procedures and measurements is long, favoring curled leaves, inadequate allocation of samples in the equipment, allowing leaves overlap (RICO-GARCÍA et al., 2009), equipment offlevel over stand or lack of adjustment on belts alignment (LI-COR ® , 1995).
From the samples of the standard figures, the values provided by USPLeaf were all equal to 9.00 cm², confirming that the software was able to provide accurate and exact estimates of area. From the estimated values of LA LI3100 , 20% of the samples were statistically higher and 40% were lower than LA USPLeaf , and the relative error rate (RER) for LA LI3100 varied from -2.42 to 3.59% ( Table  2). Values of RER varying from -5% up to 7% have been reported for LA LI3100 , being considered a low variation for the estimates of this equipment (ALI et al., 2012;KAUR et al., 2014;RADZALI;KAMAL;DIAH, 2016).
When analyzing the images of Mavuno grass leaf samples, the estimated values of LA LI3100 varied from 56.13 ± 0.18 to 113.34 ± 0.18 cm², and LA USPLeaf measurements varied from 55.17 ± 0.18 to 109.18 ± 0.18 cm². Negative RER values were registered in 80% of the samples analyzed, indicating that LA USPLeaf estimates were lower than the values provided with LA LI3100 . From the samples analyzed, 20% of the estimates were statistically higher for LA USPLeaf , 40% were higher for LA LI3100 , meanwhile non-significant differences between the leaf area (  Table 2 -Area estimated of the standard figure (black paper squares measuring 9 cm²) by using USPLeaf software (LA USPLeaf ) from images acquired with a smartphone and the standard method, using an electronic planimeter (LA LI3100 ) values were registered in 73.3% of the samples analyzed, indicating that LA USPLeaf estimates were also lower than LA LI3100 . From the samples analyzed, only 6.7% of the estimates were statistically higher for LA USPLeaf , meanwhile 66.7% were higher for LA LI3100 , and nonsignificant differences between the leaf area estimates with LA LI3100 and LA USPLeaf were obtained in 26.7% of the samples analyzed (Table 3).
The precision of measured values with LA USPLeaf can be analyzed by the range in RER, since estimates obtained are compared with a standard value. Parmar et al. (2015), registered RER values for an image processing software application varying from -4.90 to 2.18 when using LA LI3100 as the standard method, but slightly higher values of RER had been reported for image processing software applications when using graphical methods as standard, varying from 2.00 to 5.40% in Aboukarima et al. (2017), and from 3.56% to 8.12% in Li, Ji and Liu (2008).
For the present experiment, it was observed a range in RER from -6.37 to 2.25 (Table 3), and when plotted the relationship of the RER (%) and measurements provided by LA LI3100 it was not observed any effect (P>0.05) of the sample size on the RER (Figure 2), since the range in RER registered for both vegetal species can be considered low. Aboukarima et al. (2017), highlighted that RER may vary due to leaves deformation or inaccurate image acquisition procedures. Adami et al. (2008), observed by using allometric models that leaf area of soybean (Glycine max L.) leaflets (maximum length and width) was overestimated particularly for samples with damaged leaflets, but values provided by an image software  Table 3 -Leaf area estimated (cm 2 ) in Mavuno grass leaf samples and Macrotyloma axillare leaflet samples by using USPLeaf software (LA USPLeaf ) from images acquired with a smartphone and with the standard method, using an electronic planimeter (LA LI3100 ) application (Spring software) were statistically similar to those registered using the standard method. Thus, depending on the methods included in the software, processing algorithms or manually applied in the steps of filtering and noise removal, thresholding and segmentation, the holes due to insect bites, color patches as a result of diseases, nutritional deficiencies or other stresses will not be included in area measurements in digital image processing applications, but color patches as a result of diseases or nutritional deficiencies will be measured by electronic planimeters, thus affecting the RER.
Some other sources of variation on leaf area measurements and RER values may be related to the leaves physical and anatomic features. Leaf tissues traits, such as vascular bundles and xylem, number of cell layers and thickness of palisade and spongy parenchyma, epidermis as well as the cuticle affect the overall leaf thickness, can affect the leaf blade size due to changes in leaf internal temperature during the manipulation of samples. Changes in leaf blade area when exposed to different environmental temperatures are expected to be higher for plants with large and thin leaves, but for a similar form and size it may be associated to traits that delay water loss, such as the thickness of the boundary layer and cuticle, as well as leaf pilosity (LEIGH et al., 2017).
The electronic planimeter used as the standard method possesses two transparent conveyer belts that rotate to move leaves across a scanning bed. The belt system has adjustable press rollers to flatten curled leaves. The samples travel under a 15 W fluorescent light source, and the projected image is reflected by a system of three mirrors to a scanning camera (LI-COR ® , 1995). Thus, it is expected that conduction and convection heat in the belt system (favored by manipulation of samples) and radiant heat (from the mirrors and light source) possess a higher impact in Macrotyloma axillare samples (thin leaves), explaining the wider range of RER in this species (Tables  1 and 3). Care must also be taken for vegetal species with a thick central vein when using scanners for image capture (closuring the scanner), since it can provide a source of noise (FERREIRA et al., 2017) due to light leakage into the scan area. The lower impact on the area estimates of the standard figures (lower range in RER, Table 2) are probably due to the paper grammage.
The results of regression analysis indicated that the software was an accurate tool to estimate leaf area ( Figures 3A and B) Figure 3A) showed a negative intercept (-3.53 ± 2.01), but a positive value was registered in Macrotyloma axillare leaflets (1.19 ± 2.44), and both values can be considered of low magnitude, what is desirable. Furthermore, the slopes of regression were very close to 1 for both vegetal species (1.06 ± 0.02 in Mavuno grass and 1.01 ± 0.02 for Macrotyloma axillare leaflets). Since the software was planned to measure samples composed by multiple leaves, regression equations indicate that it is not recommended to measure samples lower than 25 cm² for grass leaves and 15 cm² for legume species. Whereas, USPLeaf can be used as an alternative tool to the standard methods for a wide range of vegetal species, only requiring standardization on the image acquisition procedures.  (n=45) and (B) Macrotyloma axillare leaflets (n=45) provided by USPLeaf software (LA USPLeaf ) from images acquired with a smartphone and with the standard method, using an electronic planimeter (LA LI3100 ) Figure 2 -Relationship of the relative error rate (RER, %) and leaf area measurements provided by the standard method (LI-3100, in cm 2 ) in Mavuno grass leaves and Macrotyloma axillare leaflets USPLeaf: Automatic leaf area determination using a computer vision system Improvements on software applications related to filtering for noise removal, thresholding and segmentation methods have allowed fast leaf area estimation for either destructive or non-destructive sampling with a similar accuracy to the traditional methods. Most of the existing software involves low to mid-level processing operations (GONZALEZ; WOODS, 2008). In the initial steps of image processing, some enhancement techniques, image restoration and color image processing techniques (GONZALEZ; WOODS, 2008) can be applied as automated or semi-automated procedures to separate the leaf from the image background. For the Black Spot software, described in Varma and Osuri (2013), for example, settings were developed for scanned images, and user intervention is required in defining the size of the window for applying a smoothing filter (an enhancement technique) to correct for noise or speckling in the images. Authors highlighted that the choice of window sizes provided was deliberately constrained to odd numbers (for symmetry around the focal pixel) and numbers no greater than nine, as larger window sizes may reduce the accuracy of leaf area estimates. USPLeaf software uses a fixed 3 x 3 window for applying a median filter (SHEN; NI; CHEN, 2016).
These previous steps interfere in the segmentation process. Autonomous segmentation is one of the most difficult tasks in digital image processing, and the algorithms generally are based on one or two properties of intensity values, such as discontinuity (for point, lines or edges detection) and similarity, which are made employing spectral rules operating on image band ratios, also called multiband thresholding (VARMA; OSURI, 2013), or on pixel intensities as well as other thresholding methods (GONZALEZ; WOODS, 2008). USPLeaf software operates in an entirely automated process during the image analysis, but the accuracy in the image preprocessing and segmentation steps will widely depends on the image acquisition procedures. Since the software operates using a pixel to pixel scanning algorithm to detect the ROI and the calibration scale is applied on the known area of the reference square, the height or distance between the device used for image capture and the object of interest may affect the pixel counting and the leaf area estimates. Aboukarima et al. (2017), and Rico-García et al. (2009), developed a system for image acquisition, and adopted a standard height of 45 and 40 cm, respectively, but high-resolution images would be required to ensure accuracy in the measurements. For the present software application, a height of 23 cm was defined as standard, which allows to minimize possible noises in the case of using lower resolution images (minimum image resolution recommended is 96 dpi).
Thus, advantages of digital image processing techniques such as low cost, flexibility in using several image capture devices, minimal user interventions and no dependency of electric power have making them preferable tools, particularly in field conditions, and they have widely replaced the traditional methods for leaf area measurements (allometric models, grid counting, paper weighing method, electronic planimeter or portable scanners).

CONCLUSION
Leaf area estimates of Mavuno grass leaves and Macrotyloma axillare leaflets provided by USPLeaf software showed a close and linear relationship with values of the standard method (an electronic planimeter) and, therefore, the software can be used as an automated tool in digital image processing aiming at leaf area determination on images composed by multiple leaves.