DeWAFF
Deceived Weighted Average Filters Framework Image abstraction algorithm implementation in C++
Filters Class Reference

Class containing Weighted Average Filters (WAFs). This implementation relies on padding the original image to fit square odd dimensioned kernels throughout the processing. More...

Public Member Functions

Mat BilateralFilter (const Mat &inputImage, const Mat &weightingImage, int windowSize, double spatialSigma, double rangeSigma)
 Apply a Bilateral Filter to an image. This is the decoupled version of this filter, this means that the weighting image for the filter can be different from its input image. More...
 
Mat ScaledBilateralFilter (const Mat &inputImage, const Mat &weightingImage, int windowSize, double spatialSigma, double rangeSigma)
 Apply a Scaled Bilateral Filter to an image. This is the decoupled version of this filter, this means that the weighting image for the filter can be different from its input image. The difference between this filter and the not scaled version is that the weighting image is pre scaled through a Gaussian low pass filter for better performance under heavy AWGN. More...
 
Mat NonLocalMeansFilter (const Mat &inputImage, const Mat &weightingImage, int windowSize, int neighborhoodSize, double rangeSigma)
 Apply a Non Local Means Filter to an image. This is the decoupled version of this filter, this means that the weighting image for the filter can be different from its input image. The algorithm used for this filter is computationally demanding. More...
 
Mat GuidedFilter (const Mat &inputImage, const Mat &guidingImage, int windowSize, double rangeSigma)
 Apply a Guided Filter to an image. This is the decoupled version of this filter, this means that the weighting image for the filter can be different from its input image. In this case the weighting image is known as guiding image. This filter uses a linear algorithm, making it fast computationally. More...
 

Detailed Description

Class containing Weighted Average Filters (WAFs). This implementation relies on padding the original image to fit square odd dimensioned kernels throughout the processing.

Definition at line 30 of file Filters.hpp.

Member Function Documentation

◆ BilateralFilter()

Mat Filters::BilateralFilter ( const Mat &  inputImage_,
const Mat &  weightingImage_,
int  windowSize,
double  spatialSigma,
double  rangeSigma 
)

Apply a Bilateral Filter to an image. This is the decoupled version of this filter, this means that the weighting image for the filter can be different from its input image.

Parameters
weightingImage_image used to calculate the kernel weight
inputImage_image used as input for the filter
windowSizeprocessing window size
spatialSigmaspatial standard deviation
rangeSigmarange or radiometric standard deviation
Returns
Mat output image

This filter uses two Gaussian kernels, one of them is the spatial Gaussian kernel:

\[ G_{\text spatial}(U, m, p) = \exp\left(-\frac{ ||m - p||^2 }{ 2 {\sigma_s^2} } \right) \]

with the spatial values from an image region \( \Omega \subseteq U \). The spatial kernel uses the \( m_i \subset \Omega \) pixels coordinates as weighting values for the pixel \( p = (x, y) \).

The other used kernel is the range Gaussian kernel:

\[ G_{\text range}(U, m, p) = \exp\left( -\frac{ ||U(m) - U(p)||^2 }{ 2{\sigma_r^2} } \right) \]

with the intensity (range) values from an image region \( \Omega \subseteq U \). The range kernel uses the \( m_i \subset \Omega \) pixels intensities as weighting values for the pixel \( p = (x, y) \) instead of their locations as in the spatial kernel computation. In this case a the input \( U \) is separated into the three CIELab weightChannels and each channel is processed as an individual input \( U_{\text channel} \).

The two kernels are multiplied to obtain the Bilateral Filter kernel:

\[ \psi_{\text BF}(U, m, p) = G_{\text spatial}(U, m, p) \, G_{\text range}(U, m, p) \]

The Bilateral filter's norm corresponds to:

\[ \left( \sum_{m \subset \Omega} \psi_{\text{BF}}(U, m, p) \right)^{-1} \]

Finally the bilateral filter kernel can be convolved with the input as follows:

\[ Y_{\psi_{\text BF}}(p) = \left( \sum_{m \subset \Omega} \psi_{\text BF}(U, m, p) \right)^{-1} \left( \sum_{m \subset \Omega} \psi_{\text BF}(U, p, m) \, U(m) \right) \]

Definition at line 14 of file Filters.cpp.

◆ GuidedFilter()

Mat Filters::GuidedFilter ( const Mat &  inputImage,
const Mat &  guidingImage,
int  windowSize,
double  rangeSigma 
)

Apply a Guided Filter to an image. This is the decoupled version of this filter, this means that the weighting image for the filter can be different from its input image. In this case the weighting image is known as guiding image. This filter uses a linear algorithm, making it fast computationally.

Parameters
inputImageimage used as input for the filter
guidingImageimage used to calculate the kernel's weight
windowSizeprocessing window size
rangeSigmarange or radiometric standard deviation. Used to calculate \( \epsilon = \sigma_r^2 \)
Returns
Mat

The Guided Filter initialy has the same form as any WAF

\[ q_i = \sum_j W_{ij}(I)p_j \]

where \( q_i \) is the output if filtered pixel \( p_j \) with the kernel \( W_{ij} \) guided by image \( I \). This is expected as the original idea for this filter comes from the bilateral filter. The greatness in this filter lies in its solution. It asumes a linear relationship:

\[ q_i = a_k I_i + b_k, \forall i \in \omega_k \]

where \( \omega_k \) is a window centered at pixel \( k \). The solution is in finding the linear coefficients \( a_k \) and \( b_k \). This is achieved through the cost function

\[ E(a_k, b_k) \sum_{i\in \omega_k} ((a_k I_i + b_k - p_i)^2 + \epsilon a_k^2)\]

which seeks to minimize the difference between the input \( p \) and the output \( q \). The solution is found through a linear regresion

\[ a_k = \frac{\frac{1}{|\omega|} \sum_{i\in \omega_k} I_i p_i - \mu_k \bar{p}_k}{\omega_k^2 + \epsilon}\]

\[ b_k = \bar{p}_k - a_k \mu_k \]

\( \mu_k \) and \(\omega_k^2\) are the mean and the variance of \(I\) in \( \omega_k \), respectively. \( \frac{1}{|\omega|} \sum_{i\in \omega_k} p_i \) is the mean of \(p\) in \( \omega_k \). Finally the output of the filter is

\[ q_i = \frac{1}{|\omega|} \sum_{k:i \in \omega_k} (a_k I_i + b_k )\]

Definition at line 271 of file Filters.cpp.

◆ NonLocalMeansFilter()

Mat Filters::NonLocalMeansFilter ( const Mat &  inputImage_,
const Mat &  weightingImage_,
int  windowSize,
int  neighborhoodSize,
double  rangeSigma 
)

Apply a Non Local Means Filter to an image. This is the decoupled version of this filter, this means that the weighting image for the filter can be different from its input image. The algorithm used for this filter is computationally demanding.

Parameters
weightingImage_image used to calculate the kernel's weight
inputImage_image used as input for the filter
windowSizeprocessing window size
neighborhoodSizesubwindow size
rangeSigmarange or radiometric standard deviation. Used to calculate the parameter \( h^2 = 2 \sigma_r^2 \)
Returns
Mat output image

The discrete representation of the Non Local Means Filter is as follows:

\[ \psi_{\text {NLM}}(U, m, p) = \sum_{B(m) \subseteq U} \exp\left( \frac{||B(m) - B(p)||^2 - 2 \sigma_r^2}{h^2} \right)\]

where \(B(p)\) is a patch part of the window \(\Omega\) centered at pixel \(p\). \(B(m)\) represents all of the patches at \(\Omega\) centered in each \(m\) pixel. The Non Local Means Filter calculates the Euclidean distance between each patch \(B(m)\) and \(B(p)\) for each window \(\Omega \subseteq U\). This is why this algorithm is demanding in computational terms. Each Euclidean distance matrix obtained from each patch pair is the input for a Gaussian decreasing function with standard deviation \(h\) that generates the new pixel \(p\) value.

The Non Local Means filter's norm is calculated with:

\[\left( \sum_{m \subset \Omega} \psi_{\text{NLM}}(U, m, p) \right)^{-1} \]

The NLM filter kernel is applied to the laplacian image:

\[ Y_{\psi_{\text NLM}}(p) = \left( \sum_{m \subset \Omega} \psi_{\text NLM}(U, m, p) \right)^{-1} \left( \sum_{m \subset \Omega} \psi_{\text NLM}(U, p, m) \, U(m) \right) \]

Definition at line 177 of file Filters.cpp.

◆ ScaledBilateralFilter()

Mat Filters::ScaledBilateralFilter ( const Mat &  inputImage,
const Mat &  weightingImage,
int  windowSize,
double  spatialSigma,
double  rangeSigma 
)

Apply a Scaled Bilateral Filter to an image. This is the decoupled version of this filter, this means that the weighting image for the filter can be different from its input image. The difference between this filter and the not scaled version is that the weighting image is pre scaled through a Gaussian low pass filter for better performance under heavy AWGN.

Parameters
weightingImageimage used to calculate the kernel's weight
inputImageimage used as input for the filter
windowSizeprocessing window size, has to be odd numbered and greater or equal than 3
spatialSigmaspatial standard deviation
rangeSigmarange or radiometric standard deviation
Returns
Mat output image

It uses the two same Gaussian kernels as the bilateral filter, but it has an extra input, the scaled image \( U^s \). The kernels are the following:

\[ G_{\text spatial}(U^s, U, m, p) = \exp\left(-\frac{ ||m - p||^2 }{ 2 {\sigma_s^2} } \right) \]

\[ G_{\text range}(U^s, U, m, p) = \exp\left( -\frac{ ||U^s(m) - U(p)||^2 }{ 2{\sigma_r^2} } \right) \]

Notice the diferrence on the range kernel calculation where the scaled image is used.

The two kernels are multiplied to obtain the Bilateral Filter kernel:

\[ \psi_{\text SBF}(U^s, U, m, p) = G_{\text spatial}(U^s, U, m, p) \, G_{\text range}(U^s, U, m, p) \]

The Bilateral filter's norm corresponds to:

\[ \left( \sum_{m \subset \Omega} \psi_{\text{SBF}}(U^s, U, m, p) \right)^{-1} \]

Finally the bilateral filter kernel can be convolved with the input as follows:

\[ Y_{\psi_{\text SBF}}(p) = \left( \sum_{m \subset \Omega} \psi_{\text SBF}(U^s, U, m, p) \right)^{-1} \left( \sum_{m \subset \Omega} \psi_{\text SBF}(U^s, U, m, p) \, U(m) \right) \]

Definition at line 130 of file Filters.cpp.


The documentation for this class was generated from the following files: