## 3 Autonomous Mapping and Navigation with Satellite Imagery and Cadastral Information
### First Stage: Development of the Autonomous Mapping System
#### 3.1.2 Map Creation Sub-Module  
This sub-module is in charge of creating the map of the parcel from the two images obtained in the previous sub-module. The map contains information about the parcel: trees rows, paths, and other elements where the robot cannot navigate through (i.e., obstacles). Its description can be found in Algorithm 2. ```
\(FullParcelMask\) = GenerateParcelMask[CurrentPosition,Borders] \([ParcelMask,SatImage]\) \(=\) CropImagey[FullParcelMask,FullSatImage] \([Path,\)Trees,Obstacles] = ExtractMasks[CurrentPosition,ParcelMask,SatImage]
```  
**Algorithm 2** GenerateMap{\(CurrentPosition,FullSatImage,Borders\)}  
The first step consists of determining the full parcel mask from the borders previously acquired. With the robot coordinates and the image containing the borders, this procedure generates a binary mask that represents the current parcel where the robot is located. This procedure is described in Algorithm 3. ```
Determine position \(CurrentPosition\) in Borders: \(Pos_{x}\) and \(Pos_{y}\)  Convert Borders to grayscale: \(BordersG\)  Binarize BordersG: BordersMask  Dilate BordersMask: DilatedBorder  Flood-fill DilatedBorder in \(Pos_{x},Pos_{y}\): DilatedBorder Floodfilled  Erode DilatedBorderFullfilled: \(ErodedBorder Floodfilled\)  Erode BorderFloodfilled: \(FullParcelMask\) Return:\(FullParcelMask\)
```  
**Algorithm 3** GenerateParcelMask{\(CurrentPosition,Borders\)}  
Once the parcel mask is determined from the parcel image, it is time to remove those areas outside the parcel in the satellite image and the parcel mask itself. To avoid underrepresentation of the parcels, a small offset was added to the mask. This step is performed to reduce imagery size for further treatment with advanced techniques. This procedure is detailed in Algorithm 4. Since the location of the pixels in the real world is known using the WGS84 with UTM zone 30N system (EPSG:32630), the offset between the satellite image and the parcel mask can be directly computed. Then, it is only necessary to determine the bounding box surrounding the parcel in the parcel mask to crop both images. At this point, the reduced satellite map needs to be processed to distinguish between the path and obstacles. We analyzed different satellite images from groves located in the province of Castellon in Spain, and the images were clear with little presence of shadows. Therefore, we set the binarization threshold to 112 in our work. Although we applied a manual threshold, a dynamic thresholding binarization could be applied to have a more robust method to distinguish the different elements in the satellite image, in case shadows were present. Algorithm 5 has been used to process the reduced satellite map andto obtain the following three masks or binary images:  
* _Path_--a binary mask that contains the path where the robot can navigate;
* _Trees_--a binary mask that contains the area assigned to orange trees;
* _Obstacles_--a binary mask that contains those pixels which are considered obstacles: this mask corresponds to the inverse of the path. ```
Convert \(SatImage\) to gray scale: \(SatImageGray\)  Extract \(min\) and \(max\) values of the parcel pixels in \(SatImageG\)  Normalize \(SatImageG\) values: \(SatImageGN(x,y)=255\cdot\frac{SatImageG(x,y)-MinValue}{MaxValue}\)  Generate B&W Masks: \[Path(x,y) =\left\{ \begin{array}{ll}1&\text{if }SatImageGN(x,y)>112\text{ and }ParcelMask(x,y)\\ 0&\text{otherwise}\end{array} \right.\] \[Trees(x,y) =\left\{ \begin{array}{ll}1&\text{if }SatImageGN(x,y)\leq 112\text{ and }ParcelMask(x,y)\\ 0&\text{otherwise}\end{array}