# Automated Tree Detection Using Image Processing and Multisource Data
## 4 Proposed Approach
### Algorithm and Implementation  
A custom-designed algorithm was developed to accurately detect vegetation in images. The approach was based on data acquisition, pre-processing, image analysis, and classification. Due to the fact that the original photos were not accessible, the vegetation index could not be computed, as the original infrared (IR) and visible images required for such computation were not available. Therefore, the approach relied solely on a single image. The input images gathered by the Municipal Office were color-coded using a simplified method to compute the vegetation index. With the computations already performed, the authors proposed a two-step approach. In the first step, the dominant color was identified using a 1-square-meter grid, called the Region of Interest (RoI). Then, the height difference was computed using two input.asc files--one for the absolute height of the ground level and the other for the actual height of objects within the RoI. The visualization comprised two factors: the outline color indicates the dominant color within the square, and the number inside represents the height difference. The entire concept is presented in Algorithm 1. TIFF images are the raw input files containing information about the vegetation index derived by the administration unit. The second type of input data is stored in.asc files, which include information about the ground level and height above sea level for TIFF image segments. The sizes of these segments are stored in the geoinformation files (.tfw). The proposed method is parameterized, allowing for the adjustment of selected parameters to improve the quality of the results. The key parameters and their values considered in the approach are as follows:  
* Filtering method for TIFF images: Blurring filters for removing artifacts from images were considered. Thus, besides the Gaussian filter, other filters, like the median filter, may be considered. * Kernel size for the filter: The kernel size is adjusted to control the blurring effect on the image. For tree-covered areas, the size of the kernel may be increased to achieve better results. * Set of labels for image segments: Two sets of labels were considered. The first set includes trees, buildings, and fields, while the second, more classic approach, uses a binary set \(\{tree,otherobject\}\). * Thresholds for colors and heights: These thresholds are used to adjust the labeling of image segments. ```
begin
1 INPUT: Geoinformation,.asc files, tiff image, labels FILTERING PARAMETERS: filtering method \(F\), the kernel size \(k\) LABELLING PARAMETERS color threshold \(\tilde{c}\) and height threshold \(\tilde{h}\) OUTPUT: image with labels assigned to segments
2
3 extract the segment size \((x,y)\) from geoinformation data
4 open height and ground.asc files and extract heights and grounds arrays
5 compute height differences using heights and grounds arrays
6 load tiff image \(S\) and apply the filter \(F\) with the selected kernel \(k\) divide the image as square segments (ROI) of equal size
7 foriterate over all segments \(s\) in the \(S\)do
8 calculate the average over RGB color channels as \(c_{dom}\)
9 draw a rectangle with the color that has the greatest mean on the \(s\)
10 get the ground level \(g_{l}\) value from the land-cover model
11 get the height level \(h_{l}\) from the digital terrain model
12 calculate the difference \(h_{diff}=h_{l}-g_{l}\)
13 set the segment class based on the \(c_{dom}\) and \(h_{diff}\)
14 save the output image to the output directory;
```  
**Algorithm 1**Algorithm for the label assignment for the maps. Thus, data files are initially loaded, and geoinformation, including the segment sizes on the maps \((x,y)\) in meters, is extracted. The TIFF image is divided into segments called regions of interest (RoIs) with equal sizes of \(x\) by \(y\) meters. Lines 10-16 of the algorithm present the main idea of our approach, where for every segment \(s\) in the image, \(S\) color channels are extracted, and the dominant color value \(c_{dom}\) is calculated.