## 2 Materials and Methods
### Cloud Shadow Detection and Post-Processing  
Before cloud shadow compensation, cloud shadow areas must be detected. Traditional shadows are detected using typical shadow spectral features in pixel-level segmentation. The original image is shown in a RGB color space. Since they are correlated, the original red (R)-, green (G)-, and blue (B)-band spectral information is not able to be used to detect shadows effectively. By transforming the RGB color space into a HIS color space or c1c2c3 color space, shadows show more obvious features in high-hue (H) values, low brightness (I) in the HSI color space, and high c3 values. Therefore, these are traditional shadow features in the shadow detection method. However, they do not comply with cloud shadow detection. Moreover, cloud shadows are much larger and have more serve problems of uneven shading than do the shadows of ground objects. Therefore, this paper combines multiple composite shadow features with the morphological shadow index to detect cloud shadows and involves the post-processing of a shadow to remove non-cloud-shadow regions and fill the shadow holes in cloud shadow regions. Since simple shadow features cannot combine well to detect all the shadows, we use the condition combination formula, which introduces newly designed shadow signatures and the automatic Otsu threshold strategy [37] to detect shadows. \(Q\) and \(A\) are composite features defined in (1) and (2). Using Equation (3), the initial shadows can be detected [38]. \[Q=B^{\prime}-I \tag{1}\]  
\[A=\left\{ \begin{array}{c}2B^{\prime}-I-G^{\prime},G^{\prime}\leq T\_G^{ \prime}\\ 2B^{\prime}-I-2G^{\prime},G^{\prime}>T\_G^{\prime}\end{array} \right. \tag{2}\]  
\[C_{\text{SD}}=\left\{ \begin{array}{c}(i,j)>T\_B^{\prime}\&\&\&\left(i,j \right)<T\_I\\ \left\|\left(Q(i,j)>T\_Q\&\&\&\left(i,j\right)<T\_G^{\prime}(i,j)<T\_G^{ \prime}\right)\\ \left\|A(i,j)>T\_A\right.\end{array} \right\} \tag{3}\]  
where \(I(i,j)\) represents the value of the intensity component, \(I\), in the HIS space in a pixel \((i,j)\). \(B^{\prime}\)\((i,j)\) and \(G^{\prime}\)\((i,j)\) represent the value of non-imaliized blue and nominalized green components, respectively, in the pixel \((i,j)\). \(B^{\prime}=B/(R+G+B)\), \(G^{\prime}=G/(R+G+B)\). The morphological shadow index (MSI) [39; 40], defined in Equation (4), was developed for the automatic shadow extraction of ground objects from an image at first. A distance to shadows is used as the spatial constraint of buildings, based on which some commission errors, such as open areas and bright soil, can be removed. Cloud shadows have a different distance character from buildings. This paper found that cloud shadows have a lower MSI value than buildings do. Thus, we introduce the MSI with a different algorithm to detect cloud shadows. The MSI is calculated based on the differential morphological profiles (DMP) of black top hat-transformed data, defined as \(B-TH(d,s)=\varphi_{b}^{re}(d,s)-b\). It is effective to supplement some undetected shadow areas where the spectrum features are not distinct enough to recognize shadows based on the detection conditions. \[MSI=\frac{\sum DMP_{B-TH}(d,s)}{D\cdot S} \tag{4}\]  
where \(D\) is the number of directions applied to the linear structure element (SE), and \(s\) is the size of SE. \(S=\left(\left(s_{max}-s_{min}\right)_{\Delta S}\right)+1\). \(\varphi_{b}^{re}(d,s)\) represents the closing-by-reconstruction of the brightness image. Generally, ground object shadows have larger \(MSI\) values, while the cloud shadows have smaller values. Thus, using Equation (5), the final shadows are united with the \(C_{\text{SD}}\) according to different shadow types. \[C_{\text{CloudSD}}=\left\{(i,j)|MSI(i,j)<T\_MSI\right\}\cup C_{\text{SD}} \tag{5}\]  
Lastly, the initial detection of shadow areas is incomplete, and some high-brightness areas are easy to be missed. Therefore, post-processing operations such as erasing, dilating, opening, closing, small area removal, and cavity filling are carried out on the shaded areabased on morphological methods.