Skip to content

Commit

Permalink
[DOC] Added Doxygen preprocessor commands to avoid displaying all the…
Browse files Browse the repository at this point in the history
… template predefinitions
  • Loading branch information
rlagneau authored and fspindle committed Jul 6, 2023
1 parent 31baeb7 commit c0fcfb3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 26 deletions.
64 changes: 41 additions & 23 deletions modules/core/include/visp3/core/vpImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class VISP_EXPORT vpImageFilter
/*!
Apply a 1 x size Derivative Filter in X to an image pixel.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I : Image to filter
\param r : coordinates (row) of the pixel
\param c : coordinates (column) of the pixel
Expand Down Expand Up @@ -132,7 +133,8 @@ class VISP_EXPORT vpImageFilter

/*!
Apply a size x 1 Derivative Filter in Y to an image pixel.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I : Image to filter
\param r : coordinates (row) of the pixel
\param c : coordinates (column) of the pixel
Expand All @@ -159,6 +161,7 @@ class VISP_EXPORT vpImageFilter

/*!
Apply a filter to an image.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I : Image to filter
\param If : Filtered image.
\param M : Filter kernel.
Expand Down Expand Up @@ -229,7 +232,7 @@ class VISP_EXPORT vpImageFilter
\f[
\textbf{I}_u = \textbf{M} \ast \textbf{I} \textbf{ and } \textbf{I}_v =
\textbf{M}^t \ast \textbf{I} \f]
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I : Image to filter
\param Iu : Filtered image along the horizontal axis (u = columns).
\param Iv : Filtered image along the vertical axis (v = rows).
Expand Down Expand Up @@ -289,6 +292,11 @@ class VISP_EXPORT vpImageFilter

/*!
Apply a separable filter.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I: The original image.
\param GI: The filtered image.
\param filter: The separable filter.
\param size: The size of the filter.
*/
template <typename FilterType>
static void filter(const vpImage<unsigned char> &I, vpImage<FilterType> &GI, const FilterType *filter,
Expand All @@ -302,6 +310,11 @@ class VISP_EXPORT vpImageFilter

/*!
Apply a separable filter.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I: The original image.
\param GI: The filtered image.
\param filter: The separable filter.
\param size: The size of the filter.
*/
template <typename FilterType>
static void filter(const vpImage<FilterType> &I, vpImage<FilterType> &GI, const FilterType *filter, unsigned int size)
Expand Down Expand Up @@ -873,6 +886,7 @@ class VISP_EXPORT vpImageFilter

/*!
Apply a Gaussian blur to an image.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I : Input image.
\param GI : Filtered image.
\param size : Filter size. This value should be odd.
Expand Down Expand Up @@ -901,6 +915,7 @@ class VISP_EXPORT vpImageFilter

/*!
Apply a Gaussian blur to a double image.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I : Input double image.
\param GI : Filtered image.
\param size : Filter size. This value should be odd.
Expand Down Expand Up @@ -948,7 +963,7 @@ class VISP_EXPORT vpImageFilter

/*!
Return the coefficients \f$G_i\f$ of a Gaussian filter.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param[out] filter : Pointer to the half size filter kernel that should refer to a
(size+1)/2 array. The first value refers to the central coefficient, the
next one to the right coefficients. Left coefficients could be deduced by
Expand Down Expand Up @@ -994,6 +1009,7 @@ class VISP_EXPORT vpImageFilter
Return the coefficients of a Gaussian derivative filter that may be used to
compute spatial image derivatives after applying a Gaussian blur.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param filter : Pointer to the filter kernel that should refer to a
(size+1)/2 array. The first value refers to the central coefficient, the
next one to the right coefficients. Left coefficients could be deduced by
Expand Down Expand Up @@ -1072,6 +1088,7 @@ class VISP_EXPORT vpImageFilter

/*!
Compute the gradient along X after applying a gaussian filter along Y.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I : Input image
\param dIx : Gradient along X.
\param gaussianKernel : Gaussian kernel which values should be computed using vpImageFilter::getGaussianKernel().
Expand Down Expand Up @@ -1133,6 +1150,7 @@ class VISP_EXPORT vpImageFilter

/*!
Compute the gradient along Y after applying a gaussian filter along X.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param I : Input image
\param dIy : Gradient along Y.
\param gaussianKernel : Gaussian kernel which values should be computed using vpImageFilter::getGaussianKernel().
Expand All @@ -1151,43 +1169,43 @@ class VISP_EXPORT vpImageFilter

/*!
Get Sobel kernel for X-direction.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param filter : Pointer to a double array already allocated.
\param size : Kernel size computed as: kernel_size = size*2 + 1 (max size is 20).
\return Scaling factor.
*/
template <typename T>
inline static T getSobelKernelX(T *filter, unsigned int size)
template <typename FilterType>
inline static FilterType getSobelKernelX(FilterType *filter, unsigned int size)
{
if (size == 0)
throw vpException(vpException::dimensionError, "Cannot get Sobel kernel of size 0!");
if (size > 20)
throw vpException(vpException::dimensionError, "Cannot get Sobel kernel of size > 20!");

vpArray2D<T> SobelY(size * 2 + 1, size * 2 + 1);
T norm = getSobelKernelY<T>(SobelY.data, size);
memcpy(filter, SobelY.t().data, SobelY.getRows() * SobelY.getCols() * sizeof(T));
vpArray2D<FilterType> SobelY(size * 2 + 1, size * 2 + 1);
FilterType norm = getSobelKernelY<FilterType>(SobelY.data, size);
memcpy(filter, SobelY.t().data, SobelY.getRows() * SobelY.getCols() * sizeof(FilterType));
return norm;
}

/*!
Get Sobel kernel for Y-direction.
\tparam FilterType: Either float, to accelerate the computation time, or double, to have greater precision.
\param filter : Pointer to a double array already allocated.
\param size : Kernel size computed as: kernel_size = size*2 + 1 (max size is 20).
\return Scaling factor.
*/
template <typename T>
inline static T getSobelKernelY(T *filter, unsigned int size)
template <typename FilterType>
inline static FilterType getSobelKernelY(FilterType *filter, unsigned int size)
{
// Sobel kernel pre-computed for the usual size
static const T SobelY3x3[9] = { -1.0, -2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0 };
static const T SobelY5x5[25] = { -1.0, -4.0, -6.0, -4.0, -1.0, -2.0, -8.0, -12.0, -8.0, -2.0, 0.0, 0.0, 0.0,
static const FilterType SobelY3x3[9] = { -1.0, -2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0 };
static const FilterType SobelY5x5[25] = { -1.0, -4.0, -6.0, -4.0, -1.0, -2.0, -8.0, -12.0, -8.0, -2.0, 0.0, 0.0, 0.0,
0.0, 0.0, 2.0, 8.0, 12.0, 8.0, 2.0, 1.0, 4.0, 6.0, 4.0, 1.0 };
static const T SobelY7x7[49] = { -1, -6, -15, -20, -15, -6, -1, -4, -24, -60, -80, -60, -24, -4, -5, -30, -75,
static const FilterType SobelY7x7[49] = { -1, -6, -15, -20, -15, -6, -1, -4, -24, -60, -80, -60, -24, -4, -5, -30, -75,
-100, -75, -30, -5, 0, 0, 0, 0, 0, 0, 0, 5, 30, 75, 100, 75, 30,
5, 4, 24, 60, 80, 60, 24, 4, 1, 6, 15, 20, 15, 6, 1 };
const vpArray2D<T> smoothingKernel(3, 3);
const vpArray2D<FilterType> smoothingKernel(3, 3);
smoothingKernel[0][0] = 1.0;
smoothingKernel[0][1] = 2.0;
smoothingKernel[0][2] = 1.0;
Expand All @@ -1205,25 +1223,25 @@ class VISP_EXPORT vpImageFilter

const unsigned int kernel_size = size * 2 + 1;
if (kernel_size == 3) {
memcpy(filter, SobelY3x3, kernel_size * kernel_size * sizeof(T));
memcpy(filter, SobelY3x3, kernel_size * kernel_size * sizeof(FilterType));
return 1 / 8.0;
}
if (kernel_size == 5) {
memcpy(filter, SobelY5x5, kernel_size * kernel_size * sizeof(T));
memcpy(filter, SobelY5x5, kernel_size * kernel_size * sizeof(FilterType));
return 1 / 16.0;
}
if (kernel_size == 7) {
memcpy(filter, SobelY7x7, kernel_size * kernel_size * sizeof(T));
memcpy(filter, SobelY7x7, kernel_size * kernel_size * sizeof(FilterType));
return 1 / 16.0;
}

vpArray2D<T> sobelY(7, 7);
memcpy(sobelY.data, SobelY7x7, sobelY.getRows() * sobelY.getCols() * sizeof(T));
vpArray2D<FilterType> sobelY(7, 7);
memcpy(sobelY.data, SobelY7x7, sobelY.getRows() * sobelY.getCols() * sizeof(FilterType));
for (unsigned int i = 4; i <= size; i++) {
sobelY = vpArray2D<T>::conv2(sobelY, smoothingKernel, "full");
sobelY = vpArray2D<FilterType>::conv2(sobelY, smoothingKernel, "full");
}

memcpy(filter, sobelY.data, sobelY.getRows() * sobelY.getCols() * sizeof(T));
memcpy(filter, sobelY.data, sobelY.getRows() * sobelY.getCols() * sizeof(FilterType));

return 1 / 16.0;
}
Expand Down
39 changes: 36 additions & 3 deletions modules/core/src/image/vpImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <visp3/core/vpImageFilter.h>
#include <visp3/core/vpRGBa.h>

/**
* \cond DO_NOT_DOCUMENT
*/
template<>
void vpImageFilter::filter<float>(const vpImage<unsigned char> &I, vpImage<float> &If, const vpArray2D<float> &M, bool convolve);

Expand All @@ -50,6 +53,9 @@ void vpImageFilter::filter<float>(const vpImage<float> &I, vpImage<float> &Iu, v
template <>
void vpImageFilter::filter<double>(const vpImage<double> &I, vpImage<double> &Iu, vpImage<double> &Iv, const vpArray2D<double> &M,
bool convolve);
/**
* \endcond
*/

/*!
Apply a filter to an image using two separable kernels. For instance,
Expand Down Expand Up @@ -186,6 +192,9 @@ void vpImageFilter::canny(const vpImage<unsigned char> &Isrc, vpImage<unsigned c
}
#endif

/**
* \cond DO_NOT_DOCUMENT
*/
template<>
void vpImageFilter::filter<float>(const vpImage<unsigned char> &I, vpImage<float> &GI, const float *filter,
unsigned int size);
Expand All @@ -207,6 +216,9 @@ void vpImageFilter::filterX<float>(const vpImage<unsigned char> &I, vpImage<floa
template<>
void vpImageFilter::filterX<double>(const vpImage<unsigned char> &I, vpImage<double> &dIx, const double *filter,
unsigned int size);
/**
* \endcond
*/

void vpImageFilter::filterX(const vpImage<vpRGBa> &I, vpImage<vpRGBa> &dIx, const double *filter, unsigned int size)
{
Expand All @@ -230,6 +242,9 @@ void vpImageFilter::filterX(const vpImage<vpRGBa> &I, vpImage<vpRGBa> &dIx, cons
}
}

/**
* \cond DO_NOT_DOCUMENT
*/
template<>
void vpImageFilter::filterX<float>(const vpImage<float> &I, vpImage<float> &dIx, const float *filter, unsigned int size);

Expand All @@ -243,6 +258,9 @@ void vpImageFilter::filterY<float>(const vpImage<unsigned char> &I, vpImage<floa
template<>
void vpImageFilter::filterY<double>(const vpImage<unsigned char> &I, vpImage<double> &dIy, const double *filter,
unsigned int size);
/**
* \endcond
*/

void vpImageFilter::filterY(const vpImage<vpRGBa> &I, vpImage<vpRGBa> &dIy, const double *filter, unsigned int size)
{
Expand Down Expand Up @@ -270,6 +288,9 @@ void vpImageFilter::filterY(const vpImage<vpRGBa> &I, vpImage<vpRGBa> &dIy, cons
}
}

/**
* \cond DO_NOT_DOCUMENT
*/
template<>
void vpImageFilter::filterY<float>(const vpImage<float> &I, vpImage<float> &dIy, const float *filter, unsigned int size);

Expand Down Expand Up @@ -301,6 +322,9 @@ void vpImageFilter::gaussianBlur<float>(const vpImage<unsigned char> &I, vpImage
template<>
void vpImageFilter::gaussianBlur<double>(const vpImage<unsigned char> &I, vpImage<double> &GI, unsigned int size, double sigma,
bool normalize);
/**
* \endcond
*/

/*!
Apply a Gaussian blur to RGB color image.
Expand All @@ -325,6 +349,9 @@ void vpImageFilter::gaussianBlur(const vpImage<vpRGBa> &I, vpImage<vpRGBa> &GI,
delete [] fg;
}

/**
* \cond DO_NOT_DOCUMENT
*/
template<>
void vpImageFilter::gaussianBlur<float>(const vpImage<float> &I, vpImage<float> &GI, unsigned int size, float sigma,
bool normalize);
Expand All @@ -336,9 +363,6 @@ void vpImageFilter::gaussianBlur<double>(const vpImage<double> &I, vpImage<doubl
template<>
void vpImageFilter::getGaussianKernel<float>(float *filter, unsigned int size, float sigma, bool normalize);

// template<>
// void vpImageFilter::getGaussianKernel<double>(double *filter, unsigned int size, double sigma, bool normalize);

template <>
void vpImageFilter::getGaussianDerivativeKernel<float>(float *filter, unsigned int size, float sigma, bool normalize);

Expand Down Expand Up @@ -412,6 +436,9 @@ void vpImageFilter::getGradYGauss2D<float, float>(const vpImage<float> &I, vpIma
template<>
void vpImageFilter::getGradYGauss2D<double, double>(const vpImage<double> &I, vpImage<double> &dIy, const double *gaussianKernel,
const double *gaussianDerivativeKernel, unsigned int size);
/**
* \endcond
*/

// operation pour pyramide gaussienne
void vpImageFilter::getGaussPyramidal(const vpImage<unsigned char> &I, vpImage<unsigned char> &GI)
Expand Down Expand Up @@ -487,6 +514,9 @@ void vpImageFilter::getGaussYPyramidal(const vpImage<unsigned char> &I, vpImage<
#endif
}

/**
* \cond DO_NOT_DOCUMENT
*/
template<>
double vpImageFilter::getSobelKernelX<double>(double *filter, unsigned int size);

Expand All @@ -498,3 +528,6 @@ double vpImageFilter::getSobelKernelY<double>(double *filter, unsigned int size)

template<>
float vpImageFilter::getSobelKernelY<float>(float *filter, unsigned int size);
/**
* \endcond
*/

0 comments on commit c0fcfb3

Please sign in to comment.