# Effective Implementation of Edge-Preserving Filtering on CPU Microarchitectures
## 2 Edge-Preserving Filters  
General edge-preserving filtering in finite impulse response (FIR) filtering is represented as follows:  
\[\mathbf{J}(\mathbf{p})=\frac{1}{\eta}\sum_{\mathbf{q}\in\mathcal{N}(\mathbf{p})}f(\mathbf{p},\bm {q})\mathbf{I}(\mathbf{q}), \tag{1}\]  
where \(\mathbf{I}\) and \(\mathbf{J}\) are the input and output images, respectively. \(\mathbf{p}\) and \(\mathbf{q}\) are the present and reference positions of pixels, respectively. A kernel-shaped function \(\mathcal{N}(\mathbf{p})\) comprises a set of reference pixel positions, and it varies for every pixel \(\mathbf{p}\). The function \(f(\mathbf{p},\mathbf{q})\) denotes the weight of position \(\mathbf{p}\) with respect to the position \(\mathbf{q}\) of the reference pixel. \(\eta\) is a normalizing function. If the gain of the FIR filter is one, we set the normalizing function as follows:  
\[\eta=\sum_{\mathbf{q}\in\mathcal{N}(\mathbf{p})}f(\mathbf{p},\mathbf{q}). \tag{2}\]  
Various types of weight functions are employed in edge-preserving filtering. These weights are composed of spatial and range kernels or only a range kernel. The weight of the bilateral filter is expressed as follows:  
\[f(\mathbf{p},\mathbf{q}) := \exp(\frac{\|\mathbf{p}-\mathbf{q}\|_{2}^{2}}{-2\sigma_{s}^{2}})\exp( \frac{\|\mathbf{I}(\mathbf{p})-\mathbf{I}(\mathbf{q})\|_{2}^{2}}{-2\sigma_{r}^{2}}), \tag{3}\]  
where \(\|\cdot\|_{2}\) is the L2 norm and \(\sigma_{s}\) and \(\sigma_{r}\) are the standard deviations of the spatial and the range kernels, respectively. The weight of the non-local means filter is as follows:  
\[f(\mathbf{p},\mathbf{q}) := \exp(\frac{\|\mathbf{v}(\mathbf{p})-\mathbf{v}(\mathbf{q})\|_{2}^{2}}{-h^{2}}), \tag{4}\]where \(\mathbf{v}(\mathbf{p})\) represents a vector, which includes a square neighborhood of the center pixel \(\mathbf{p}\). \(h\) is a smoothing parameter. The weight of the bilateral filter is determined by considering the similarity between the color and spatial distance between a target pixel and that of the reference pixel. The weight of the non-local means filter is defined by computing the similarity between the patch on the target pixel and that on the reference pixel. The weight of the non-local means filter is similar to the range weight of the bilateral filter for a multi-channel image.  
To discuss the influence of the denormalized numbers, we introduce two variants of the bilateral and non-local means filters, namely the Gaussian range filter and the bilateral non-local means filter. The weight of the Gaussian range filter is expressed as follows:  
\[f(\mathbf{p},\mathbf{q}) := \exp(\frac{\|\mathbf{I}(\mathbf{p})-\mathbf{I}(\mathbf{q})\|_{2}^{2}}{-2\sigma_{ r}^{2}}). \tag{5}\]  
The weight of the bilateral non-local means filter [43] is as follows:  
\[f(\mathbf{p},\mathbf{q}) := \exp(\frac{\|\mathbf{p}-\mathbf{q}\|_{2}^{2}}{-2\sigma_{s}^{2}})\exp( \frac{\|\mathbf{v}(\mathbf{p})-\mathbf{v}(\mathbf{q})\|_{2}^{2}}{-h^{2}}). \tag{6}\]  
The Gaussian range filter is composed of the range kernel alone in the bilateral filtering. The bilateral non-local means filter is composed of the spatial kernel and the range kernel in the non-local means filtering.