## 2 Methodology
### Sun Detection
#### 2.2.2. Dome Detection
An example of dome detection is shown in Figure 3.  
```
1:procedureFindDome(\(B(m,n)\), \(\Delta y\), \(m,n\))
2:\(w=n/2\)
3:\(h=m/2\)
4:\(\text{first}=True\)
5:\(\text{second}=True\)
6:\(\text{third}=True\)
7:for\(j=1\) to \((m/2)\)do
8:if\(B\left(h,w-j\right)\) is equal to \(1\) and first then
9:\(P_{1}=\left\{h,w-j\right\}\)
10:\(\text{first}=False\)
11:endif
12:if\(B\left(h,w+j\right)\) is equal to \(1\) and second then
13:\(P_{2}=\left\{h,w+j\right\}\)
14:\(\text{second}=False\)
15:endif
16:if\(B\left(h-\Delta y,w-j\right)\) is equal to \(1\) and third then
17:\(P_{3}=\left\{h-\Delta y,w-j\right\}\)
18:\(\text{third}=False\)
19:endif
20:if first is equal to \(False\) and second is equal to \(False\) and third is equal to \(False\) then
21:break
22:endif
23:endfor
24:\(\left(P_{dome},\ r_{dome}\right)=\textsc{DomeParameters}(P_{1},P_{2},P_{3})\)
25:return\(\left(P_{dome},\ r_{dome}\right)\)
26:endprocedure
27:procedureDomeParameters(\(P_{1},P_{2},P_{3}\))
28:\(\left\{x_{1},y_{1}\right\}=P_{1}\)
29:\(\left\{x_{2},y



It is important to mention that this step is done only when the first image is acquired. Once the dome is detected, the system is ready to find the Sun within the ROI. #### 2.2.3 Clear Sky Sun Segmentation

The ideal case to make the detection of the position of the Sun is when a sunny day is presented, since there are no elements in the sky that interfere with the detection. This process is identified on the block called Sun segmentation from the diagram shown in Figure 2. The needed sequence of steps performed by the system to get the Sun's position in the image are shown in the diagram of Figure 4.

In order to compute the Sun's position, the system begins with a color space conversion from RGB to HSL; let \(H(m,n,p)\) be the new image representation. HSL is another color space, which represents the color on three channels: hue, saturation, and brightness (how bright the color is). Thus, objects with very large brightness values can be easily separated from the background in the image. From the image \(H(m,n,p)\), where in this case, \(p=3\), which represents the brightness channel in the image, the system performs thresholding over it and then a binarization. This threshold value is chosen based on the histogram of the image pixel intensities. From this operation, the matrix \(B_{H}\) is obtained, this matrix contains dark values in the object zone and white values in the background. The resulting image is shown in Figure 4(b), where the objects segmented are the those with the highest brightness. From each object found, the system computes the minimum enclosing circle to get the center, as well as the radius; let \(C=\{c_{1}(x_{c_{1}},y_{c_{1}},r_{c_{1}}),\ldots,c_{n}(x_{c_{n}},y_{c_{n}},r_{ c_{n}})\}\) be the set of detected circles, where \((x_{c_{i}},y_{c_{i}})\) represents the center coordinates and \(r_{c_{i}}\) the radius of the \(i^{\text{th}}\) circle (\(c_{i}\)). To discriminate the Sun from all those objects found in the segmentation process, Algorithm 2 has been implemented. Figure 4: Sun segmentation based on image processing. Figure 3: Dome detection example. The input color image, as well as the dome detection are shown in (a,b), respectively. ```
1:procedureSunSearching(C,\(P_{dome}\),\(r_{dome}\),\(MaxSunRadius\),\(MinSunRadius\))
2:\(n=|C|\)
3:for\(i=1\) to \(n\)do
4:\(P_{i},r_{i}=c_{i}(x_{c_{i}},y_{c_{i}},r_{c_{i}})\)
5:\(d=\left\|P_{i},P_{dome}\right\|\)
6:if\(d<r_{dome}\)and\((MinSunRadius<r_{i}<MaxSunRadius)\)then
7:\(c_{Sun}=c_{i}\)
8:else
9:\(c_{Sun}=(0,0,0)\)
10:endif
11:endfor
12:return\(c_{Sun}\)
13:endprocedure
```

**Algorithm 2** Sun-searching algorithm. The input parameters of Algorithm 2 are the detected circles \(C\), the center and radius of the detected dome, and a max and min radius of the Sun, which have been determined experimentally.