## 3 Method
### Shadow Compensation
#### 3.3.2 Edge Fusion  
Directly replacing the compensated shadow areas with the original image can lead to visible seams at the boundary. Additionally, due to the attenuation of the shadow component at the edges, the binary shadow detection map cannot fully encompass areas with fewer shadow components. To address this issue, we propose an edge fusion method based on the p-Laplacian operator, ensuring a smooth transition between shadowed and non-shadowed areas and maintaining consistency in spectral characteristics. To tackle the issue of transitions at the shadow boundary, we use a preprocessing step, which applies a Gaussian blur to the shadow mask \(A\):  
\[A_{blurred}=G_{\sigma}*A \tag{12}\]  
where \(G_{\sigma}\) represents a Gaussian filter with a standard deviation of \(\sigma\), and \(*\) denotes the convolution operation. The input image \(I_{Input}\) for the edge fusion method is  
\[I_{Input}=A_{blurred}\cdot I_{\text{Exposure}}+(1-A_{blurred})\cdot I \tag{13}\]  
The p-Laplacian operator is constructed based on the first-order gradient \(U_{x}\), \(U_{y}\) and second-order gradient \(U_{xx}\), \(U_{xy}\), \(U_{yx}\), \(U_{yy}\) of the image. \[U_{zz}=\frac{U_{y}^{2}\cdot U_{xx}-2\cdot U_{x}\cdot U_{y}\cdot U_{xy}+U_{x}^ {2}\cdot U_{yy}}{U_{x}^{2}+U_{y}^{2}} \tag{14}\]\[U_{nn}=\frac{U_{x}^{2}\cdot U_{xx}+2\cdot U_{x}\cdot U_{y}\cdot U_{xy}+U_{y}^{2} \cdot U_{yy}}{U_{x}^{2}+U_{y}^{2}} \tag{15}\]  
The p-Laplacian operator is expressed as follows  
\[PLop=(\sqrt{U_{x}^{2}+U_{y}^{2}})^{-0.5}\cdot(U_{zz}+0.5\cdot U_{nn}) \tag{16}\]  
For the input image \(I_{Input}\), the p-Laplacian operator \(PLop\) is applied channel-wise, resulting in the edge feature map. Areas with high values of the edge feature map indicate rapid changes in spectral values, probably representing regions in which the shadow boundary is not coherently fused. To identify areas requiring edge fusion, we perform dilation and erosion operations on the shadow mask \(A\) to obtain pixel regions \(A_{p}\) that cover shadow edges. Subsequently, we execute fusion operations in this area. First, we need to initialize the confidence of pixels, setting the confidence of pixels to be processed to 1 and the confidence of pixels that do not require processing to 0. The initial expression of the confidence term \(Conf\) is  
\[Conf(x,y)= \begin{cases}1,&\text{if }(x,y)\in A_{p}\\ 0,&\text{Otherwise}\end{cases}  \tag{17}\]  
The fusion operation needs to start from the outer edge pixels and gradually progress towards the center of the area. By applying a \(3\times 3\) Laplacian filter to \(A_{p}\), some pixels near the edge are identified. By comparing the priorities of these pixels, they are selected for fusion in sequence. The priority of pixels is composed of data item \(D\) and confidence item \(Conf\), where data item \(D\) is the value of the corresponding pixel in the edge feature map generated by the p-Laplacian operator. The expression is as follows  
\[Priority(x,y)=Conf(x,y)\cdot D(x,y) \tag{18}\]  
After identifying the pixel with the highest priority, the best matching pixel is chosen from a \(9\times 9\) patch centered around it, based on the input image \(I_{Input}\). This optimal match takes into account spectral differences and the spatial distance for replacing the pixel with the highest priority. After updating the pixel, the confidence term \(Conf\) and data term \(D\) must also be updated, and the pixel is no longer considered a candidate pixel. To update the confidence \(Conf\) of a given pixel \((p_{x},p_{y})\), we take a patch of \(9\times 9\) centered on this pixel. We calculate the average confidence of certain pixels in this patch as the new confidence for \((p_{x},p_{y})\). The pixels used for calculation only include pixels that do not require processing or have already been processed.