# Non-Local Means Hole Repair Algorithm Based on Adaptive Block
## 2 Depth Image Inpainting Algorithm
### Hole Filling Algorithm Based on Non-Local Means  
Section 2.2 introduces the NLM hole-repairing algorithm, a block-based method selected for its unique approach to depth image repair. Unlike traditional pixel-based methods, NLM leverages vector-centered repairs and maximizes the use of redundant information in the image. This section outlines the fundamental principles of the NLM algorithm and its application to depth image hole filling. The NLM Algorithm is a block-based method for depth image hole repair that considers the hole points as the centers and utilizes surrounding search blocks as processing units. By calculating the similarity between different repair blocks and the repair block centered at the hole point, similar weights are assigned to each repaired pixel. Then, a weighted average is employed to estimate the repaired depth value of the hole points. The NLM algorithm, which is different from traditional restoration methods based on individual pixels, uses the vector centered at the hole point for repair and makes full use of the redundant information in the image. The algorithm maximally preserves image details and enables efficient and accurate repair of in-depth images. The relationship between the search blocks and repair blocks of the hole point \(x\) and its neighboring non-hole point \(y\) is illustrated in Figure 2.  
According to Figure 2, it can be observed that the depth values within the holes are strongly correlated with non-hole points distributed in the neighborhood of the holes. Additionally, since the holes in-depth images often appear in the edge regions of objects, utilizing a single-point calculation for repair weights cannot effectively distinguish between points situated at the object edges and those within the smooth interior regions of objects. This leads to a certain degree of computational error. The proposed algorithm addresses this issue by computing similarity weights using vectors centered around the points within the holes rather than relying on individual pixels. This approach enhances the robustness of the algorithm in handling hole repair, providing a more accurate and reliable solution. The weights in the NLM algorithm are composed of three components: grayscale similarity, distance similarity, and repairing weight. Grayscale similarity weight refers to the degree of likeness in grayscale values between the target hole point \(x\) within the grayscale image and the non-hole point \(y\) within the search block \(A(x)\). The distance similarity weight concerns the extent of proximity between the remaining points within \(A(x)\) and its central point. The computation of the repairing weight for each \(y\) within \(A(x)\) is determined through the collaborative influence of grayscale weight and distance weight, thereby quantifying the similarity of depth values between \(x\) and \(y\). The grayscale similarity weight can be described as follows:  
\[g(x,y)=e^{-\frac{\frac{1}{2}\left(N_{A}\right)-v(N_{y})\right|_{x=d}^{2}}{h^{2}}} \tag{1}\]  
where \(h\) is the decay rate of the grayscale weight \(v(N_{x})\) and \(v(N_{y})\) represents the vectors of \(x\) and \(y\), respectively. These two vectors are composed of pixels from the repair blocks centered at \(x\) and \(y\), with a size of \(q\times q\), denoted as \(B(x)\) and \(B(y)\) respectively. And the val  
Figure 2: Illustration of the search block and the repair block. ues are listed from left to right and from top to bottom. The Gaussian-weighted Euclidean distance is denoted by \(\|\cdot\|_{2,a}^{2}\), where \(a\) is the standard deviation of the Gaussian kernel. The distance similarity weight can be described as follows:  
\[d(x,y)=e^{-\frac{\|x-y\|^{2}}{e^{2}}} \tag{2}\]  
where \(\sigma\) controls the decay rate of the exponential function and \(\|\cdot\|^{2}\) represents the Euclidean distance between points \(x\) and \(y\).