# Effective Implementation of Edge-Preserving Filtering on CPU Microarchitectures
## 5 Proposed Methods for the Prevention of Denormalized Numbers  
An edge-preserving filter has a range kernel and a spatial kernel or only a range kernel. When the similarity of color intensity is low, and the spatial distance is long, the weight of the kernel is exceedingly small. For example, in the bilateral filter for a color image, when the parameters are \(\sigma_{r}=32\), \(\mathbf{I}(\mathbf{p})=(255,255,255)\) and \(\mathbf{I}(\mathbf{q})=(0,0,0)\), the range weight is \(4.29\times 10^{-42}\), which is the minimum value of the range kernel and is a denormalized number in float. Note that the remaining spatial kernel does not multiply the weight. Thus, the total value becomes smaller than the range weight. Moreover, the non-local means filtering is more likely to involve denormalized numbers from Equation (4). Notably, the occurrence frequency of denormalized numbers is low when the smoothing parameters are large. This parameter overly smooths edge-parts; thus, the smoothing parameters should be small in most cases. We propose new methods to prevent the occurrence of denormalized numbers for the edge-preserving filtering. The proposed methods deal with the two cases: a weight function contains only one term or multiple terms. For the former cases, we consider two implementations: computing directly and referring to only one LUT. For the latter cases, we also consider two implementations: computing directly and referring to each of multiple LUTs. For the one-term case, the argument of the term is clipped using appropriate values so that the resulting value is not a denormalized number. If the weight function is a Gaussian distribution, the argument value \(x\) satisfies the following equations:  
\[\exp(x) > \delta_{max},\] \[x > \ln(\delta_{max}), \tag{9}\]  
Figure 2: Set and gather instructions: (**a**) set instruction; (**b**) gather instruction. where \(\delta_{max}\) is the maximum value of the denormalized number. In other words, Equation (9) can be written as follows:  
\[x \geq \ln(\
u_{min}), \tag{10}\]  
where \(\
u_{min}\) denotes the minimum value of the normal number. \(\delta_{max}\) and \(\
u_{min}\) are set based on the precision of floating point numbers. In the proposed method, an argument value is clipped by \(-87.3365478515625=\ln(\
u_{min})\) in float. For the multiple terms, the clipping method is inadequate because denormalized numbers could occur owing to the multiplication of multiple terms. Therefore, the weights are multiplied by an offset value in the proposed method. The offset value satisfies the following equations:  
\[o\times\prod_{n}^{N}\min_{x\in\Lambda_{n}}w_{n}(x)>\delta_{max}, \tag{11}\] \[\frac{\
u_{max}}{255|\mathcal{N}(\mathbf{p})|}\geq o\times\prod_{n}^{ N}\max_{x\in\Lambda_{n}}w_{n}(x),\] (12) \[\
u_{max}\geq o>\delta_{max}, \tag{13}\]  
where \(o\) is an offset value and \(w_{k}\) is the \(k\)-th weight function, which is a part of the decomposed weight function. \(N\) is the number of terms in the weight function. \(\Lambda_{k}\) is a set of possible arguments in the \(k\)-th weight function, and \(\
u_{max}\) is the maximum value of normal numbers. Equation (12) limits the summation in Equation (1) such that it does not exceed the normal number when the image range is 0-255. Notably, \(\min_{x}w_{n}(x)\) and its product are occasionally zero owing to underflow, even if the mathematical results of the weight function are non-zero. When the number of terms is large or \(\min_{x}w_{n}(x)\) is very small, \(o\) is very large. Therefore, Equations (12) and (13) cannot be satisfied. In this condition, we must reduce the number of significant figures of \(w_{n}(\cdot)\) to eliminate the occurrence of denormalized numbers. Note that \(o\) should be large to ensure that the number of significant figures of \(w_{n}(\cdot)\) is large. In the edge-preserving filtering, \(\max_{x}w_{n}(x)\) is one.