Development of a QGIS Plugin to Obtain Parameters and Elements of Plantation Trees and Vineyards with Aerial Photographs

Unmanned Aerial Vehicle (UAV) imagery allows for a new way of obtaining geographic information. In this work, a Geographical Information System (GIS) open source application was developed in QGIS software that estimates several parameters and metrics on tree crown through image analysis techniques (image segmentation and image classification) and fractal analysis. The metrics that have been estimated were: area, perimeter, number of trees, distance between trees, and a missing tree check. This methodology was tested on three different plantations: olive, eucalyptus, and vineyard. The application developed is free, open source and takes advantage of QGIS integration with external software. Several tools available from Orfeo Toolbox and Geographic Resources Analysis Support System (GRASS) GIS were employed to generate a classified raster image which allows calculating the metrics referred before. The application was developed in the Python 2.7 language. Also, some functions, modules, and classes from the QGIS Application Programming Interface (API) and PyQt4 API were used. This new plugin is a valuable tool, which allowed for automatizing several parameters and metrics on tree crown using GIS analysis tools, while considering data acquired by UAV.


Introduction
Remote sensing techniques provide useful information for agricultural management enhancing the reliable automation of mapping procedures [1].In recent years, Unmanned Aerial Vehicle (UAV) imagery has allowed a new way of getting geographic information from remote sensing data [2].UAV technology provides several advantages compared to a manned aircraft such as: (i) significantly lower qualification requirements for UAV pilots; (ii) allows for mapping small areas, resulting in very high spatial resolution (VHR) images, which are ideal for detecting small objects; (iii) low cost acquisition; and, (iv) it can couple different sensors [2].UAVs are increasingly used in different contexts and in several research areas, such in cartography, environmental studies, cultural heritage, civil engineering, forestry, and agriculture/precision agriculture [3][4][5][6][7][8].Therefore, when considering UAV imagery, it is possible to acquire information more efficiently and inexpensively [9].UAV imagery have been used to estimate metrics from trees in several crops or farms, which can be of interest of farmers in order to obtain a better planning of the irrigation process, helping in the forecast of the production date and climate change effects as a consequence of deforestation and degradation of forests, which leads to global warming, precision forestry, forest management planning, and biomass estimation [2,[10][11][12][13].Most of the work conducted with UAV data has been related with forest areas [11,12,[14][15][16][17][18][19].However, in the field of agriculture crops, it is relevant to study the geometric characterization of trees and plantations.This is a complex task, being particularly important to understand the tree growth and productivity [1,9,13,[20][21][22].In the field of precision agriculture, several image processing methods for automatic detection and delineation of individual trees were already implemented [1].The information regarding tree crown areas of a specific crop is the key in the study of ecological value and ratio of the occupied area by that crop [9,15,23].Traditionally, tree counting has been performed manually based on field information and statistical data, being an expensive process, time consuming, and a tedious task subject to several errors [13,14,22].Satellite, manned aircraft, or UAV imagery can be used to obtain these data.Therefore, the implementation of automatic processes is crucial to extract information and provide forest or crops inventories from remote sensing data [2,13,22].
Several studies have been developed with different techniques to estimate the tree crown delineation, tree counting, and tree characterization from remote sensing imagery.Deng et al. [23] proposed an artificial intelligence algorithm based on seeded based region growth method to extract tree crown from Quickbird satellite images.In this work, after the segmentation process, a condition regarding the Normalized Difference Vegetation Index (NDVI > 0.38) was considered.Santoro et al. [1] proposed an algorithm based on an asymmetric weighted kernel optimized for tree counting using GeoEye-1 satellite imagery.Park et al. [10] developed a tree isolation algorithm based on aerial imagery for precise tree detection and crown delineation.Through UAV imagery acquired from a Hexacoptor, Bazi et al. [2] extracted a set of candidate key points using Scale Invariant Feature Transform (SIFT) analyzed with the Extreme Learning Machine (ELM), which is a kernel-based classification method.Processing operations using mathematical morphology were used to distinguish palm trees from other type of vegetation.Kang et al. [9] proposed an identification method for tree crown areas from imagery captured by UAV.The methodology was based on mathematical morphological filtering, unsupervised segmentation based on J-value SEGmentation (JSEG), local spatial statistics and Iterative Self-Organizing Data Analysis Technique Algorithm (ISODATA).Panagiotidis et al. [24] used the Structure from motion (Sfm) approach to generate a point cloud that was used to calculate a Digital Surface Model (DSM) and an orthomosaic.This information was used as input data for tree crown delineation using local maxima filtering (for tree heights) and Inverse Watershed Segmentation (IWS) for tree crown detection.Thiel and Schmullius [17] also used Sfm for generating remote sensing products from UAV imagery and LASTools software package to generate the point cloud.The tree detection was based on pit-free Canopy Height Models.Hassaan et al. [11] created a script in Matlab to remove barrel distortions from UAV images, k-means clustering in the segmentation stage, and texture analysis.Finally, to count the trees a circle fitting approximation technique was used.Nevalainen et al. [12] investigated the performance of UAV and hyperspectral imagery in individual tree detection and tree species classification in forests computing the spectral features using Matlab.Chianucci et al. [25] used Red-Green-Blue (RGB) UAV images to segment tree canopies (tree/non tree mask) based on visible-vegetation indices and colour space conversion and conclude that the true colour UAV images can be effectively used to obtain meaningful estimations of forest crown attributes.
Object-Based Image Analysis (OBIA) has proven to be a valuable approach to image segmentation and classification when considering the form, color, and textures of the pixels, minimizing the boundary problem [22,[26][27][28][29]. OBIA groups the local homogeneous pixels, i.e., it allows for mapping the VHR imagery into meaningful objects [27].
In the referred studies proprietary software were considered.However, there are several open source software available such as Spring, Orfeo ToolBox (OTB)/Monteverdi, GRASS and QGIS which are complemented with processing image algorithms [28].The open source Geographical Information System (GIS) software, such as QGIS, presented some advantage since it integrates algorithms from OTB and GRASS through Processing Toolbox framework [30][31][32][33].The UAV imagery can be considered as an input in GIS applications as it provides the tools that are required to correctly manipulate, analyze, and incorporate geographic information.In fact, the open source concept implies the creation/development of new applications.For instance, Grippa et al. [34] presented a semi-automated processing chain, developed in Python language, for object-based land-cover and land-use classification ISPRS Int.J. Geo-Inf.2018, 7, 109 3 of 20 using GRASS GIS and R open source software.Also, Duarte et al. [35] developed a GIS open source application for image processing automatizing the photogrammetric procedures, such as computing tie points between pairs of images, computing relative orientations based on calibration models, sparsing three-dimensional (3D) models, generating orthomosaics, point cloud, DSM, and shaded reliefs, through the integration of MicMac open source software in QGIS.
The objective of this work was the creation of a GIS open source application/plugin-Tree Crown-that estimates several parameters and metrics on tree crown through image analysis techniques (image segmentation and classification) and fractal analysis.
The innovation of this work is highlighted by: (i) the literature analysis-there is not a GIS application available that provides specifically the metrics regarding tree crown; (ii) the developing and implementation of the methodology in a new plugin, so the users that are not familiar with the algorithms presents in QGIS software can, easily, estimate the parameters with a simple tool; (iii) the GIS application was developed in Python language, which is a free programming language, so that it allows for the modification or adaptation by any user according to specific rules; (iv) we respect the freedoms of open source software using QGIS software which provide the possibility of incorporating algorithms and functions from others software; and, (v) the fractal analysis was only feasible with an automatic implementation.

Study Case
Three study cases were considered: an orthomosaic from an olive crop acquired with an UAV imagery with 2.75 ha (Mirandela, Bragança, Portugal in August 2016, 41 •  concept implies the creation/development of new applications.For instance, Grippa et al. [34] presented a semi-automated processing chain, developed in Python language, for object-based land-cover and land-use classification using GRASS GIS and R open source software.Also, Duarte et al. [35] developed a GIS open source application for image processing automatizing the photogrammetric procedures, such as computing tie points between pairs of images, computing relative orientations based on calibration models, sparsing three-dimensional (3D) models, generating orthomosaics, point cloud, DSM, and shaded reliefs, through the integration of MicMac open source software in QGIS.
The objective of this work was the creation of a GIS open source application/plugin-Tree Crown-that estimates several parameters and metrics on tree crown through image analysis techniques (image segmentation and classification) and fractal analysis.
The innovation of this work is highlighted by: (i) the literature analysis-there is not a GIS application available that provides specifically the metrics regarding tree crown; (ii) the developing and implementation of the methodology in a new plugin, so the users that are not familiar with the algorithms presents in QGIS software can, easily, estimate the parameters with a simple tool; (iii) the GIS application was developed in Python language, which is a free programming language, so that it allows for the modification or adaptation by any user according to specific rules; (iv) we respect the freedoms of open source software using QGIS software which provide the possibility of incorporating algorithms and functions from others software; and, (v) the fractal analysis was only feasible with an automatic implementation.

Data Acquisition
The image corresponding to each study case was obtained with a rotary-wing UAV (3DR Solo) with a MicaSense RedEdge camera which is composed by five bands: Red, Green, Blue, Red edge, and Near-Infrared (NIR).The coordinate reference system adopted was Universal Transverse Mercator (UTM) Zone 29 North-World Geodetic System 1984 (WGS84; EPSG:32629) for olive crop image (with a spatial resolution of 2.8 cm), and European Terrestrial Reference System 1989 (ETRS89) Portugal Transverse Mercator 2006 (PTTM06; EPSG:3763) for eucalypt (with a spatial resolution of 3.6 cm) and vineyard images (with a spatial resolution of 5.2 cm).It was performed one single cloud-free flight to each study case.The flight height to olive crop was 50 m, for eucalypt was 120 m and for vineyard was 80 m.After, for each image, the NDVI was computed using Red and NIR bands [36].

Data Acquisition
The image corresponding to each study case was obtained with a rotary-wing UAV (3DR Solo) with a MicaSense RedEdge camera which is composed by five bands: Red, Green, Blue, Red edge, and Near-Infrared (NIR).The coordinate reference system adopted was Universal Transverse Mercator (UTM) Zone 29 North-World Geodetic System 1984 (WGS84; EPSG:32629) for olive crop image (with a spatial resolution of 2.8 cm), and European Terrestrial Reference System 1989 (ETRS89) Portugal Transverse Mercator 2006 (PTTM06; EPSG:3763) for eucalypt (with a spatial resolution of 3.6 cm) and vineyard images (with a spatial resolution of 5.2 cm).It was performed one single cloud-free flight to each study case.The flight height to olive crop was 50 m, for eucalypt was 120 m and for vineyard was 80 m.After, for each image, the NDVI was computed using Red and NIR bands [36].

GIS Software, Python Libraries and Tree Crown Application
The application was created and implemented in QGIS software (version 2.18 Las Palmas), an open source software, which consider the Stallman four freedoms, namely the possibility to study and modify the code, to distribute the program with different modified versions [32,33].QGIS allows for the development of new plugins in Python 2.7 programming language [37] and provide online support through forums, tutorials, and documentation [33].It allows for vector and raster files manipulation, visualization, analysis, and acquisition.To create a new plugin, different libraries and/or Application Programming Interface (API) are commonly used, such as Geographic Resources Analysis Support System (GRASS), QGIS API, and PyQt4 API [30,38,39].Also, from QGIS 2.0, a Processing Toolbox, a framework containing several algorithms of standalone GIS software, such as GRASS 7.2.2 and OTB 5.0.0, was integrated [31].The OTB software is an open source project for remote sensing and it is composed by several algorithms, which allows for processing high resolution, multispectral, and RADAR images, and includes several image processing procedures, such as ortho-rectification, pan sharpening, classification algorithms, image manipulation, and segmentation [31].
This plugin was concretized as a button in QGIS main menu.The plugin graphic interface was developed through Qt Designer package where it is possible to create and personalize the widgets such as combo boxes, push buttons, labels, among others [40].
The main graphic interface is a window composed by four fields, two inputs and two outputs (Figure 2).This fields were defined as push buttons and line edits.The functions related to each push button are, respectively, inputfile, inputfile2, output, and output2.The main procedure was implemented in the function run.In this function the image details, such as extension, number of bands and multispectral bands, were accessed using functions from QgsRasterLayer() class [38].In order to access to Processing Toolbox algorithms, the Processing module was imported and the function runAlgorithm() was used.The experimental procedure performed allowed to select the most accurate methodology to be implemented in the plugin.The methodology implementation is described in the Section 3.2.1,Section 3.2.2, and Section 3.2.3.

GIS Software, Python Libraries and Tree Crown Application
The application was created and implemented in QGIS software (version 2.18 Las Palmas), an open source software, which consider the Stallman four freedoms, namely the possibility to study and modify the code, to distribute the program with different modified versions [32,33].QGIS allows for the development of new plugins in Python 2.7 programming language [37] and provide online support through forums, tutorials, and documentation [33].It allows for vector and raster files manipulation, visualization, analysis, and acquisition.To create a new plugin, different libraries and/or Application Programming Interface (API) are commonly used, such as Geographic Resources Analysis Support System (GRASS), QGIS API, and PyQt4 API [30,38,39].Also, from QGIS 2.0, a Processing Toolbox, a framework containing several algorithms of standalone GIS software, such as GRASS 7.2.2 and OTB 5.0.0, was integrated [31].The OTB software is an open source project for remote sensing and it is composed by several algorithms, which allows for processing high resolution, multispectral, and RADAR images, and includes several image processing procedures, such as ortho-rectification, pan sharpening, classification algorithms, image manipulation, and segmentation [31].
This plugin was concretized as a button in QGIS main menu.The plugin graphic interface was developed through Qt Designer package where it is possible to create and personalize the widgets such as combo boxes, push buttons, labels, among others [40].
The main graphic interface is a window composed by four fields, two inputs and two outputs (Figure 2).This fields were defined as push buttons and line edits.The functions related to each push button are, respectively, inputfile, inputfile2, output, and output2.The main procedure was implemented in the function run.In this function the image details, such as extension, number of bands and multispectral bands, were accessed using functions from QgsRasterLayer() class [38].In order to access to Processing Toolbox algorithms, the Processing module was imported and the function runAlgorithm() was used.The experimental procedure performed allowed to select the most accurate methodology to be implemented in the plugin.The methodology implementation is described in the Sections 3.2.1,3.2.2, and 3.2.3.

Procedures Tested
To define the methodology to be implemented in the plugin, different tools were tested and compared.In the end, the more accurate methodology was chosen.Based on the literature consulted and in the tools existing in QGIS, the OBIA classification approach was chosen.The Sections 3.2.1 and 3.2.2describe the tools that are available in QGIS to perform OBIA segmentation and classification.

Procedures Tested
To define the methodology to be implemented in the plugin, different tools were tested and compared.In the end, the more accurate methodology was chosen.Based on the literature consulted and in the tools existing in QGIS, the OBIA classification approach was chosen.The Sections 3.2.1 and 3.2.2describe the tools that are available in QGIS to perform OBIA segmentation and classification.

OBIA Segmentation
For the segmentation process, two algorithms from GRASS and OTB, respectively, i.segment and Watershed segmentation were tested.The first approach performs the segmentation based in the region growing algorithm and the second uses the watershed algorithm [41].The i.segment sequentially examines all of the segments in the raster file and calculates a similarity measure between the current segment and each of its neighbors, according to a given distance [30].This algorithm was computed considering two parameters: the thresholding, which represents the similarity between 0 and 1; and, the object minimum size (minsize), which corresponds to the minimum size value that each object can have.In thresholding, a higher value aggregates objects with similar properties.Through a neighbor relation, the pixels that presented similar spectral and spatial characteristics to the seed points were aggregated, dividing the image into objects.
When considering the region growing method, different values of thresholding and minsize were tested in order to optimize the procedure.The thresholding was tested with values ranging from 0.05 to 0.95 (unitless), in which a loop cycle was created, and where the first image created (with 0.05 of thresholding) contained the seed points and the following images were obtained recursively from the first one; was considered an increment in thresholding value of 0.05 [41].Also, the minsize value was randomly tested when considering the values 10, 100, and 200.In this segmentation process, the tool accepts the multispectral image with separated bands and with non-separated bands as inputs.The other parameters were defined by default.
The Watershed segmentation algorithm from OTB was tested with the default values that were provided by QGIS [33].
In Section 4.1.1,the results that were obtained with the two algorithms tested will be presented.The more robust algorithm implemented was the i.segment.In the Tree Crown application, to split the multispectral image by bands, the split image, algorithm from OTB, was employed.The first seed image was processed with 0.05 of thresholding.Then, a for loop was created to use i.segment algorithm with an increment of 0.05 and the thresholding values varied between 0.1 and 0.65.The final image was obtained considered a thresholding of 0.65.

OBIA Classification
In image classification, two algorithms, from OTB, were tested: supervised classification using the Image classification algorithm, through the Support Vector Machine (SVM) classifier, and unsupervised classification through the Unsupervised kmeans image classification algorithm [42,43].
In the supervised classification, the mean and standard deviation values of each band were obtained from a XML file generated from Compute images second order statistics algorithm from OTB.The next step consisted in a shapefile creation with two training areas: the tree crown class (assigning as 1) and remaining objects (assigning as 0).The SVM method was used through TrainImagesClassifier (svm), algorithm from OTB, to perform classifier training from pairs of images [30].Finally, the classification was performed using the Image Classification algorithm with the multispectral image and the NDVI image as inputs, and the XML file containing the mean and standard deviation values, the segmented image generated before and the SVM resulting file [42].The classification accuracy was obtained through r.kappa algorithm from GRASS GIS 7, which compute the error matrix of the classification result by crossing the classified map layer with respect to reference map layer (training areas).The error matrix and the kappa value were returned.
In the unsupervised classification (k-means algorithm), the clusters (center points of each class) are defined and the pixels are classified based on their distance to the cluster.When considering that the NIR or RED bands from low-cost UAV sensors are usually less radiometrically robust than RGB bands, the multispectral image, the NDVI image, and the RGB true colour combination were used as inputs into the classification process.The training areas were defined with the Training set size parameter, assuming the value of 100,000 pixels [44].The validation mask corresponded to the segmented image and the other parameters were defined by default.
The classification algorithm chosen was the unsupervised classification algorithm implemented through the Unsupervised kmeans image classification from OTB.In this algorithm the input can be the RGB combination, the multispectral or the NDVI image, and the segmented image as validation mask.
The training set size parameter was obtained when multiplying the total number of pixels by 0.00705 to obtain the value 100,000 and the remaining parameters were defined by default.Then, the maximum value of the resulted image was extracted and associated to the tree crown using functions from QgsRasterLayer().To distinguish the tree crown from the other objects, the Rastercalculator, algorithm from GDAL, was used, assigning the value 1 to tree crown.The image obtained was converted to shapefile through Polygonize algorithm, from GDAL, which was interpreted using functions from QgsVectorLayer() class.To restrict the objects only to tree crown, were not considered: (i) objects with an area lower than 1 m 2 or higher than 50 m 2 ; (ii) elements with the class value different from 1; and, (iii) objects with the ratio between height and width of the polygon bounding box, which is considered as a regular polygon where the extension values (x minimum, x maximum, y minimum, and y maximum) correspond to the extension of an irregular polygon.In the case of tree crown, it is expected a quadrangular polygon, so this ratio should be closest to 1.However, in this plugin, a tolerance of 0.55 was considered.The ratio was obtained implementing a for loop to extract the area, height and width.In the end, the features, which satisfy at least one of the above criteria, were excluded from the shapefile.

Fractal Analysis
The fractal analysis was applied in order to obtain the tree crown parameters and metrics in shapefile format.To perform this, the resulting image from OBIA need to be converted to binary image, where 1 corresponded to the tree crown and 0 to the remaining objects.The resulted image was then converted to shapefile through Polygonize, algorithm from Geospatial Data Abstraction Library (GDAL) [45].The area was estimated, and the tree crown objects were identified when considering an area between 1 m 2 and 50 m 2 .
In the GIS application, the fractal analysis was generated and included in a text file composed by the following metrics: area, perimeter, centroid of each tree, total number of trees, total area of tree crown, and total number of missing trees.The information was saved in table format with the following headers: Id, Area, Perimeter, x (centroid) and y (centroid).
The code that was implemented used the write() function to insert each parameter.Through functions from QgsVectorLayer() class, the Id attribute was added to the shapefile attribute table.Two for loops were created to count the number of trees, sum the total area of tree crown, and to extract the trees metrics.To obtain the distance between the trees in each row, it was necessary to estimate the rhumb value.Because the trees positions are not regular, the rhumb between each tree was calculated using the azimuth function from QgsPoint() class.It was considered the positive rhumb.This value was calculated considered all of the centroids.From the list obtained, the mode value of the rhumb was extracted.Then, two for loops were defined to calculate the rhumb of one point related with the other points to find the distances in the existent rows, with a tolerance of 10.The minimum distance, which corresponds to the distance between two consecutive points in the same row, was extracted and listed.These values allowed for detecting the missing trees.For that, the mean distance was obtained and, if a distance value was higher than the mean value, with a specific tolerance of 1.5, a missing tree was detected.Finally, the total number of trees, the total area, the mean distance between trees and the number of missing trees was recorded in the text file.

Experimental Procedure
In order to define the methods to be implemented in the new plugin, some tests were performed in the segmentation and classification stages when considering the olive crop.This (Section 4) section presents the results obtained in these tests.

OBIA Segmentation
Figure 3 presents the segmentation result obtained with i.segment algorithm (Figure 3a) and considered the Watershed algorithm (Figure 3b), both performed when considering the default values.Several tests were computed using different values of thresholding and minsize.Table 1 presents the results obtained regarding the tests that were performed using different values of thresholding (0.65 or 0.95) and minsize (10, 100, or 200) for segmentation process and different inputs (multispectral image, RGB image, or NDVI) for classification process with i.segment algorithm.Also, the algorithm can be applied with separated bands or joined bands.So, the tests presented considered these two cases.
Table 1 presents the results of several tests performed considered the multispectral image, Several tests were computed using different values of thresholding and minsize.Table 1 presents the results obtained regarding the tests that were performed using different values of thresholding (0.65 or 0.95) and minsize (10, 100, or 200) for segmentation process and different inputs (multispectral image, RGB image, or NDVI) for classification process with i.segment algorithm.Also, the algorithm can be applied with separated bands or joined bands.So, the tests presented considered these two cases.
Table 1 presents the results of several tests performed considered the multispectral image, NDVI image and RGB true colour image as inputs in unsupervised classification.For this study case, the results obtained considering the multispectral image and the RGB image presented worst accuracy when compared with NDVI image (as input).For this reason, the NDVI image was used as input.
The segmentation accuracy was evaluated based on "Goodness for fit" statistical model, as provided by i.segment algorithm, which allows for describing how well it fits a set of observations, summarizing the discrepancy between observed and expected values.In the GRASS library (i.segment algorithm), this parameter is based on the distance of the pixel to the object that it belongs to.A value of 1 means identical values, a perfect fit, and a value of 0 means maximum possible distance, worst possible fit.Given the lack of field data to validate the results obtained, this model was used.In order to estimate the percentage of pixels with specific values, r.report (algorithm from GRASS) was computed.The model was applied to the segmentation tests that were performed in Table 1.Based on the report that was returned it was concluded that: in case (a) all of the image pixels were above 0.96 and 47.33% of them were above 0.99; in case (b) all of the pixels were above 0.94 and 69.82% of the pixels were above 0.99; in the case (c) all the pixels were above 0.95 and 44.85% of them were above 0.99; in case (d) all the pixels were above 0.93 and 73.79% of them were above 0.99; in case (e) all the pixels were above 0.95 and 44.85% were; in case (f) all the pixels were above 0.97 and 64.94% of them were above 0.99.The values obtained proved that the segmentation using i.segment algorithm was satisfactory.Figure 4 presents an example of "Goodness for fit" map.
ISPRS Int.J. Geo-Inf.2018, 7, x FOR PEER REVIEW 9 of 20 accuracy when compared with NDVI image (as input).For this reason, the NDVI image was used as input.
The segmentation accuracy was evaluated based on "Goodness for fit" statistical model, as provided by i.segment algorithm, which allows for describing how well it fits a set of observations, summarizing the discrepancy between observed and expected values.In the GRASS library (i.segment algorithm), this parameter is based on the distance of the pixel to the object that it belongs to.A value of 1 means identical values, a perfect fit, and a value of 0 means maximum possible distance, worst possible fit.Given the lack of field data to validate the results obtained, this model was used.In order to estimate the percentage of pixels with specific values, r.report (algorithm from GRASS) was computed.The model was applied to the segmentation tests that were performed in Table 1.Based on the report that was returned it was concluded that: in case (a) all of the image pixels were above 0.96 and 47.33% of them were above 0.99; in case (b) all of the pixels were above 0.94 and 69.82% of the pixels were above 0.99; in the case (c) all the pixels were above 0.95 and 44.85% of them were above 0.99; in case (d) all the pixels were above 0.93 and 73.79% of them were above 0.99; in case (e) all the pixels were above 0.95 and 44.85% were; in case (f) all the pixels were above 0.97 and 64.94% of them were above 0.99.The values obtained proved that the segmentation using i.segment algorithm was satisfactory.Figure 4 presents an example of "Goodness for fit" map.The i.segment presented consistent results (Figure 3a), whereas the results that were obtained with the OTB algorithm were not satisfactory (Figure 3b).For this reason, the i.segment algorithm was chosen to be implemented in the plugin.The tests performed with different thresholding and minsize values allowed to define the more adequate methodology (Table 1).The thresholding parameter was defined as 0.65 as it presented a significant agglomeration of the pixels in the objects with smaller values.The minsize value was defined as 100 pixels as the results obtained were better with smaller values and very similar with higher values (Table 1).The i.segment presented consistent results (Figure 3a), whereas the results that were obtained with the OTB algorithm were not satisfactory (Figure 3b).For this reason, the i.segment algorithm was chosen to be implemented in the plugin.The tests performed with different thresholding and minsize values allowed to define the more adequate methodology (Table 1).The thresholding parameter was defined as 0.65 as it presented a significant agglomeration of the pixels in the objects with smaller values.The minsize value was defined as 100 pixels as the results obtained were better with smaller values and very similar with higher values (Table 1).

OBIA Classification
In this process, both classification, supervised and unsupervised, obtained similar results, as presented in Figure 5.The input defined in the supervised classification (Figure 5a) was the multispectral image, because the NDVI image did not presented valid results.Regarding the classification accuracy, in the supervised classification was obtained an overall accuracy of 92.84% and a kappa value of 0.71.While in the unsupervised classification the NDVI image presented results more robust (Figure 5b).Both classifications used the segmented image with separated bands as input.As both provided very similar results, the algorithm that was implemented in the plugin was the unsupervised classification because it is a procedure more objective when compared to the supervised classification, given the fact that the user doesn't need to define the training areas to classify.The input defined in the supervised classification (Figure 5a) was the multispectral image, because the NDVI image did not presented valid results.Regarding the classification accuracy, in the supervised classification was obtained an overall accuracy of 92.84% and a kappa value of 0.71.While in the unsupervised classification the NDVI image presented results more robust (Figure 5b).Both classifications used the segmented image with separated bands as input.As both provided very similar results, the algorithm that was implemented in the plugin was the unsupervised classification because it is a procedure more objective when compared to the supervised classification, given the fact that the user doesn't need to define the training areas to classify.
The final result was obtained from a segmentation through i.segment algorithm using the multispectral image with separated bands, followed by an unsupervised classification through Unsupervised kmeans image classification when considering the NDVI image as input (Figure 5a).

Fractal Analysis
The classified image was then converted to binary image using Raster Calculator, resulting in an image with values 1 to tree crown and 0 to the remaining objects.After, this image was converted to shapefile (Figure 6).
ISPRS Int.J. Geo-Inf.2018, 7, x FOR PEER REVIEW 13 of 20 The final result was obtained from a segmentation through i.segment algorithm using the multispectral image with separated bands, followed by an unsupervised classification through Unsupervised kmeans image classification when considering the NDVI image as input (Figure 5a).

Fractal Analysis
The classified image was then converted to binary image using Raster Calculator, resulting in an image with values 1 to tree crown and 0 to the remaining objects.After, this image was converted to shapefile (Figure 6).In the shapefile showed in Figure 6, some objects were not correctly classified.Based on in situ knowledge, objects with an area different from (1-50) m 2 or objects with an atypical shape for the general tree crown should be removed.The remaining objects are considered as tree crown (Figure 5b).

GIS Open Source Application
To test the plugin created, the study case presented in the experimental procedure was considered.The result obtained was the shapefile with the tree crown and the text file with the metrics estimated.Figure 7a  In the shapefile showed in Figure 6, some objects were not correctly classified.Based on in situ knowledge, objects with an area different from (1-50) m 2 or objects with an atypical shape for the general tree crown should be removed.The remaining objects are considered as tree crown (Figure 5b).

GIS Open Source Application
To test the plugin created, the study case presented in the experimental procedure was considered.The result obtained was the shapefile with the tree crown and the text file with the metrics estimated.Figure 7a,b present the resulting shapefile from plugin and the shapefile obtained manually, respectively.
ISPRS Int.J. Geo-Inf.2018, 7, x FOR PEER REVIEW 13 of 20 The final result was obtained from a segmentation through i.segment algorithm using the multispectral image with separated bands, followed by an unsupervised classification through Unsupervised kmeans image classification when considering the NDVI image as input (Figure 5a).

Fractal Analysis
The classified image was then converted to binary image using Raster Calculator, resulting in an image with values 1 to tree crown and 0 to the remaining objects.After, this image was converted to shapefile (Figure 6).In the shapefile showed in Figure 6, some objects were not correctly classified.Based on in situ knowledge, objects with an area different from (1-50) m 2 or objects with an atypical shape for the general tree crown should be removed.The remaining objects are considered as tree crown (Figure 5b).

GIS Open Source Application
To test the plugin created, the study case presented in the experimental procedure was considered.The result obtained was the shapefile with the tree crown and the text file with the metrics estimated.Figure 7a,b present the resulting shapefile from plugin and the shapefile obtained manually, respectively.The code implemented allowed for removing the objects with a bounding box higher than the ratio defined.The metrics estimated presented a total count of 178 trees and a total area of 1401.3 m 2 .The mean distance between the trees was 7.8 m and it were detected 23 missing trees.
In the plugin testing phase some limitations were founded.For instance, two trees were wrongly removed and some of them were not totally separated.The proximity between them was not detected by the algorithm (Figure 8).
ISPRS Int.J. Geo-Inf.2018, 7, x FOR PEER REVIEW 14 of 20 The code implemented allowed for removing the objects with a bounding box higher than the ratio defined.The metrics estimated presented a total count of 178 trees and a total area of 1401.3 m 2 .The mean distance between the trees was 7.8 m and it were detected 23 missing trees.
In the plugin testing phase some limitations were founded.For instance, two trees were wrongly removed and some of them were not totally separated.The proximity between them was not detected by the algorithm (Figure 8).Also, some vegetation species with similar spectral characteristics with olives were wrongly identified as olive crop (Figure 9).The detected number of missing trees seems to be higher than the expected.This fact can be related with the roads that cross this area, so it was identified as a missing tree (Figure 10).Two different crops were also used to test the plugin, eucalyptus, and vineyards.In the case of eucalyptus, the resulted shapefile was not satisfactory, because most of the trees were not recognized and some shadows were identified as trees (Figure 11).
In this study case, some polygons were not completely separated, because the eucalyptus trees are very close together.Also, the shade of the trees is different, so it was not possible to obtain a Also, some vegetation species with similar spectral characteristics with olives were wrongly identified as olive crop (Figure 9).The code implemented allowed for removing the objects with a bounding box higher than the ratio defined.The metrics estimated presented a total count of 178 trees and a total area of 1401.3 m 2 .The mean distance between the trees was 7.8 m and it were detected 23 missing trees.
In the plugin testing phase some limitations were founded.For instance, two trees were wrongly removed and some of them were not totally separated.The proximity between them was not detected by the algorithm (Figure 8).Also, some vegetation species with similar spectral characteristics with olives were wrongly identified as olive crop (Figure 9).The detected number of missing trees seems to be higher than the expected.This fact can be related with the roads that cross this area, so it was identified as a missing tree (Figure 10).Two different crops were also used to test the plugin, eucalyptus, and vineyards.In the case of eucalyptus, the resulted shapefile was not satisfactory, because most of the trees were not recognized and some shadows were identified as trees (Figure 11).
In this study case, some polygons were not completely separated, because the eucalyptus trees are very close together.Also, the shade of the trees is different, so it was not possible to obtain a The detected number of missing trees seems to be higher than the expected.This fact can be related with the roads that cross this area, so it was identified as a missing tree (Figure 10).The code implemented allowed for removing the objects with a bounding box higher than the ratio defined.The metrics estimated presented a total count of 178 trees and a total area of 1401.3 m 2 .The mean distance between the trees was 7.8 m and it were detected 23 missing trees.
In the plugin testing phase some limitations were founded.For instance, two trees were wrongly removed and some of them were not totally separated.The proximity between them was not detected by the algorithm (Figure 8).Also, some vegetation species with similar spectral characteristics with olives were wrongly identified as olive crop (Figure 9).The detected number of missing trees seems to be higher than the expected.This fact can be related with the roads that cross this area, so it was identified as a missing tree (Figure 10).Two different crops were also used to test the plugin, eucalyptus, and vineyards.In the case of eucalyptus, the resulted shapefile was not satisfactory, because most of the trees were not recognized and some shadows were identified as trees (Figure 11).
In this study case, some polygons were not completely separated, because the eucalyptus trees are very close together.Also, the shade of the trees is different, so it was not possible to obtain a Two different crops were also used to test the plugin, eucalyptus, and vineyards.In the case of eucalyptus, the resulted shapefile was not satisfactory, because most of the trees were not recognized and some shadows were identified as trees (Figure 11).
ISPRS Int.J. Geo-Inf.2018, 7, x FOR PEER REVIEW 15 of 20 homogeneous colour maybe due to the light conditions.In this test, 558 eucalyptuses were detected and an area of 2632.1 m 2 was estimated.The mean distance obtained was 14.9 m and 101 eucalyptuses were not identified.
In vineyard crop study case, some species vegetation and other trees, different from vineyard, were identified.In this case, 254 trees were identified and 886.3 m 2 of area was obtained.The mean distance was 13.3 m and 41 trees were missing (Figure 12).From the results obtained, testing the plugin with different plantations, some limitations were founded.These limitations could be overcome with the use of DSM, which can be generated from UAV imagery.Several studies proved that, with the DSM, it is possible to achieve a good performance in the extraction of individual tree metrics [46].The plantation background is relevant to understand the accuracy of the results obtained with this plugin.As in olive crop some shrubs were wrongly identified as olives (Figure 9).In these cases, the DSM could help into distinguish tree crowns from the surrounding vegetation more reliably.In the future a new method should be implemented in this plugin integrating the DSM in the that is methodology proposed.In this study case, some polygons were not completely separated, because the eucalyptus trees are very close together.Also, the shade of the trees is different, so it was not possible to obtain a homogeneous colour maybe due to the light conditions.In this test, 558 eucalyptuses were detected and an area of 2632.1 m 2 was estimated.The mean distance obtained was 14.9 m and 101 eucalyptuses were not identified.
In vineyard crop study case, some species vegetation and other trees, different from vineyard, were identified.In this case, 254 trees were identified and 886.3 m 2 of area was obtained.The mean distance was 13.3 m and 41 trees were missing (Figure 12).homogeneous colour maybe due to the light conditions.In this test, 558 eucalyptuses were detected and an area of 2632.1 m 2 was estimated.The mean distance obtained was 14.9 m and 101 eucalyptuses were not identified.
In vineyard crop study case, some species vegetation and other trees, different from vineyard, were identified.In this case, 254 trees were identified and 886.3 m 2 of area was obtained.The mean distance was 13.3 m and 41 trees were missing (Figure 12).From the results obtained, testing the plugin with different plantations, some limitations were founded.These limitations could be overcome with the use of DSM, which can be generated from UAV imagery.Several studies proved that, with the DSM, it is possible to achieve a good performance in the extraction of individual tree metrics [46].The plantation background is relevant to understand the accuracy of the results obtained with this plugin.As in olive crop some shrubs From the results obtained, testing the plugin with different plantations, some limitations were founded.These limitations could be overcome with the use of DSM, which can be generated from UAV imagery.Several studies proved that, with the DSM, it is possible to achieve a good performance in the extraction of individual tree metrics [46].The plantation background is relevant to understand the accuracy of the results obtained with this plugin.As in olive crop some shrubs were wrongly identified as olives (Figure 9).In these cases, the DSM could help into distinguish tree crowns from the surrounding vegetation more reliably.In the future a new method should be implemented in this plugin integrating the DSM in the that is methodology proposed.

Processing Time
In order to compare the performance of the plugin developed, processing time of the experimental tests were recorded (Table 2), for olive crop.These procedures were performed in the same environment: same computer, same CPU (Intel ® , Santa Clara, CA, USA, Core™ i7-5500U CPU@ 2.40 GHz), same memory (8.00 GB) and same operating system (Windows 10 Home, Microsoft, Seattle, WA, USA).The objective of this analysis was to evaluate the performance of the plugin created comparing the processing time of it with the manual procedure.Several conclusions can be drawn when considering the results that are presented in Table 2.The total processing time was calculated when considering three different segmentation methods.The Watershed algorithm took 6 39 .The segmentation with i.segment, defined with the default values, took 31 57 and the segmentation with the thresholding takes 34 57 .The plugin processing time was also recorded and took 35 18 .From the manual procedures, the algorithm implemented in the plugin (with thresholding method) was the slowest method.However, the evaluation of the results that were obtained in this work proved that the i.segment with thresholding were the most satisfactory approach.The processing time was similar with the segmentation performed manually or with the plugin using the i.segment with thresholding.Even though the manual processing took less 21 than the automatized processing implemented in the plugin, it must be considered that the manual processing was performed step by step and the plugin ran all of the algorithms automatically in one step.Furthermore, the fractal analysis including the estimation of the number of trees, the total area of the tree crown, the centroid of a tree, the perimeter and the total number of missing trees were implemented in the plugin automatizing this process.A method was defined where the missing trees are automatically detected, which improved the plugin capabilities, as this process can be very complex to perform without a specific script.When combining this with the high quality of the results obtained, this methodology proved to be the best one and was chosen to be implemented in the plugin.
The total processing time of the plugin for eucalyptus and vineyards resulted in 3 h 30 31 and 1 h 20 18 , respectively.These results proved that the processing time depends on the crop used and the image size.

Conclusions
The automatic trees detection using a UAV image is a complex process.Different types of objects can be identified in the UAV images, so it is required a robust algorithm to detect the correct objects.UAV technology combined with GIS software proved to be efficient in the detection of tree crown, as it combines tools to visualize, manipulate, analyse and process geographic information data acquired by UAVs.The open source GIS software, as QGIS, provides the possibility of developing new plugins in order to automatize procedures and integrates several external algorithms, for instance, processing image algorithms.This functionality allowed for developig/creating a new plugin with the implementation of the more accurate methodology to obtain the parameters/metrics of tree crown.In this work, a new plugin was created automatizing the process of obtaining the parameters/metrics of tree crown.Different methodologies were tested and the more accurate was implemented in the plugin.To evaluate the performance of the plugin, the time processing of the set of procedures implemented was compared with the manual procedure.From the results that were obtained, it was concluded that the methodology implemented in the segmentation stage using i.segment with thresholding method presented the most satisfactory result in terms of processing time and accuracy.However, some limitations were founded in the code implemented, which were related to the precise identification of trees of a specific crop.Therefore, in the future, the plugin can be improved with a more efficient code and new methods.For instance, it can be improved when considering: (i) the correctly overlap of the bands; (ii) to use hyperspectral images instead of multispectral images, as the hyperspectral images presents continuous values allowing for a better distinction between the objects; (iii) to provide morphological operations, such as erosion to remove surrounding pixels and dilatation of the objects adding pixels to the surrounding areas; (iv) added supervised classification algorithms; and, (v) incorporation of DSM in the methodology.This plugin was created in the context of plantations, however the plugin presents a huge potential for other different areas such in small-crop delineations (cabbage fields, strawberries plantations, among others) or even non-environmental applications such as counting cars or buildings.The greater advantages of the developed plugin are the possibility of estimating the parameters with a simple and intuitive tool, not requiring the knowledge of the algorithms existent in QGIS and the possibility of the incorporation of algorithms and functions from others software.The first version of this tool is presented in this paper.The plugin is free, open source and available in http://www.fc.up.pt/pessoas/liaduarte/treecrown.rar.

Figure 3 Figure 3 .
Figure3presents the segmentation result obtained with i.segment algorithm (Figure3a) and considered the Watershed algorithm (Figure3b), both performed when considering the default values.

Figure 4 .
Figure 4. "Goodness for fit" map considering a thresholding of 0.65 and a minsize of 100, with separated bands.

Figure 4 .
Figure 4. "Goodness for fit" map considering a thresholding of 0.65 and a minsize of 100, with separated bands.

Figure 6 .
Figure 6.Shapefile with tree crown well identified.

Figure 7 .
Figure 7. (a) Shapefile obtained with the plugin; and, (b) shapefile obtained with the manual process.

Figure 6 .
Figure 6.Shapefile with tree crown well identified.

Figure 6 .
Figure 6.Shapefile with tree crown well identified.

Figure 7 .
Figure 7. (a) Shapefile obtained with the plugin; and, (b) shapefile obtained with the manual process.Figure 7. (a) Shapefile obtained with the plugin; and, (b) shapefile obtained with the manual process.

Figure 7 .
Figure 7. (a) Shapefile obtained with the plugin; and, (b) shapefile obtained with the manual process.Figure 7. (a) Shapefile obtained with the plugin; and, (b) shapefile obtained with the manual process.

Figure 10 .
Figure 10.Representation of the road that cross the study area, which can influence the results.

Figure 10 .
Figure 10.Representation of the road that cross the study area, which can influence the results.

Figure 10 .
Figure 10.Representation of the road that cross the study area, which can influence the results.

Figure 10 .
Figure 10.Representation of the road that cross the study area, which can influence the results.

Table 2 .
Processing time of manually procedure and plugin.