34 #ifndef _vpImageFilter_h_
35 #define _vpImageFilter_h_
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpImageException.h>
50 #include <visp3/core/vpMath.h>
51 #include <visp3/core/vpMatrix.h>
52 #include <visp3/core/vpRGBa.h>
54 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC)
55 #include <opencv2/imgproc/imgproc.hpp>
56 #include <opencv2/imgproc/imgproc_c.h>
71 float thresholdCanny,
unsigned int apertureSobel);
74 float lowerThresholdCanny,
float higherThresholdCanny,
unsigned int apertureSobel);
85 return (2047.0 * (I[r][c + 1] - I[r][c - 1]) + 913.0 * (I[r][c + 2] - I[r][c - 2]) +
86 112.0 * (I[r][c + 3] - I[r][c - 3])) / 8418.0;
98 return (2047.0 * (I[r + 1][c] - I[r - 1][c]) + 913.0 * (I[r + 2][c] - I[r - 2][c]) +
99 112.0 * (I[r + 3][c] - I[r - 3][c])) / 8418.0;
115 template <
class T,
typename FilterType>
123 for (i = 1; i <= (size - 1) / 2; i++) {
124 result += filter[i] * (I[r][c + i] - I[r][c - i]);
142 template <
class T,
typename FilterType>
150 for (i = 1; i <= (size - 1) / 2; i++) {
151 result += filter[i] * (I[r + i][c] - I[r - i][c]);
184 template <
typename FilterType>
188 unsigned int half_size_y = size_y / 2, half_size_x = size_x / 2;
193 for (
unsigned int i = half_size_y; i < I.
getHeight() - half_size_y; i++) {
194 for (
unsigned int j = half_size_x; j < I.
getWidth() - half_size_x; j++) {
197 for (
unsigned int a = 0; a < size_y; a++) {
198 for (
unsigned int b = 0; b < size_x; b++) {
199 FilterType val = I[i + half_size_y - a][j + half_size_x - b];
200 conv += M[a][b] * val;
208 for (
unsigned int i = half_size_y; i < I.
getHeight() - half_size_y; i++) {
209 for (
unsigned int j = half_size_x; j < I.
getWidth() - half_size_x; j++) {
212 for (
unsigned int a = 0; a < size_y; a++) {
213 for (
unsigned int b = 0; b < size_x; b++) {
214 FilterType val = I[i - half_size_y + a][j - half_size_x + b];
215 corr += M[a][b] * val;
236 template <
typename FilterType>
238 bool convolve =
false)
240 unsigned int size = M.
getRows();
241 unsigned int half_size = size / 2;
247 for (
unsigned int v = half_size; v < I.
getHeight() - half_size; v++) {
248 for (
unsigned int u = half_size; u < I.
getWidth() - half_size; u++) {
249 FilterType conv_u = 0;
250 FilterType conv_v = 0;
252 for (
unsigned int a = 0; a < size; a++) {
253 for (
unsigned int b = 0; b < size; b++) {
254 FilterType val = I[v + half_size - a][u + half_size - b];
255 conv_u += M[a][b] * val;
256 conv_v += M[b][a] * val;
265 for (
unsigned int v = half_size; v < I.
getHeight() - half_size; v++) {
266 for (
unsigned int u = half_size; u < I.
getWidth() - half_size; u++) {
267 FilterType conv_u = 0;
268 FilterType conv_v = 0;
270 for (
unsigned int a = 0; a < size; a++) {
271 for (
unsigned int b = 0; b < size; b++) {
272 FilterType val = I[v - half_size + a][u - half_size + b];
273 conv_u += M[a][b] * val;
274 conv_v += M[b][a] * val;
294 template <
typename FilterType>
298 filterX<FilterType>(I, GIx, filter, size);
299 filterY<FilterType>(GIx, GI, filter, size);
311 template <
typename FilterType>
315 filterX<FilterType>(I, GIx, filter, size);
316 filterY<FilterType>(GIx, GI, filter, size);
322 return (
unsigned char)((1. * I[i][j - 2] + 4. * I[i][j - 1] + 6. * I[i][j] + 4. * I[i][j + 1] + 1. * I[i][j + 2]) / 16.);
326 return (
unsigned char)((1. * I[i - 2][j] + 4. * I[i - 1][j] + 6. * I[i][j] + 4. * I[i + 1][j] + 1. * I[i + 2][j]) / 16.);
329 template <
typename FilterType>
333 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
334 for (
unsigned int j = 0; j < (size - 1) / 2; j++) {
335 dIx[i][j] = vpImageFilter::filterXLeftBorder<FilterType>(I, i, j, filter, size);
337 for (
unsigned int j = (size - 1) / 2; j < I.
getWidth() - (size - 1) / 2; j++) {
338 dIx[i][j] = vpImageFilter::filterX<FilterType>(I, i, j, filter, size);
340 for (
unsigned int j = I.
getWidth() - (size - 1) / 2; j < I.
getWidth(); j++) {
341 dIx[i][j] = vpImageFilter::filterXRightBorder<FilterType>(I, i, j, filter, size);
346 template<
typename FilterType>
350 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
351 for (
unsigned int j = 0; j < (size - 1) / 2; j++) {
352 dIx[i][j] = vpImageFilter::filterXLeftBorder<FilterType>(I, i, j, filter, size);
354 for (
unsigned int j = (size - 1) / 2; j < I.
getWidth() - (size - 1) / 2; j++) {
355 dIx[i][j] = vpImageFilter::filterX<FilterType>(I, i, j, filter, size);
357 for (
unsigned int j = I.
getWidth() - (size - 1) / 2; j < I.
getWidth(); j++) {
358 dIx[i][j] = vpImageFilter::filterXRightBorder<FilterType>(I, i, j, filter, size);
368 template<
typename FilterType>
375 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
376 result += filter[i] * (I[r][c + i] + I[r][c - i]);
378 return result + filter[0] * I[r][c];
381 static inline double filterXR(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
387 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
388 result += filter[i] * (I[r][c + i].R + I[r][c - i].R);
390 return result + filter[0] * I[r][c].R;
393 static inline double filterXG(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
399 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
400 result += filter[i] * (I[r][c + i].G + I[r][c - i].G);
402 return result + filter[0] * I[r][c].G;
405 static inline double filterXB(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
411 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
412 result += filter[i] * (I[r][c + i].B + I[r][c - i].B);
414 return result + filter[0] * I[r][c].B;
417 template <
typename FilterType>
419 const FilterType *filter,
unsigned int size)
425 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
427 result += filter[i] * (I[r][c + i] + I[r][c - i]);
429 result += filter[i] * (I[r][c + i] + I[r][i - c]);
431 return result + filter[0] * I[r][c];
435 const double *filter,
unsigned int size)
441 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
443 result += filter[i] * (I[r][c + i].R + I[r][c - i].R);
445 result += filter[i] * (I[r][c + i].R + I[r][i - c].R);
447 return result + filter[0] * I[r][c].R;
451 const double *filter,
unsigned int size)
457 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
459 result += filter[i] * (I[r][c + i].G + I[r][c - i].G);
461 result += filter[i] * (I[r][c + i].G + I[r][i - c].G);
463 return result + filter[0] * I[r][c].G;
467 const double *filter,
unsigned int size)
473 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
475 result += filter[i] * (I[r][c + i].B + I[r][c - i].B);
477 result += filter[i] * (I[r][c + i].B + I[r][i - c].B);
479 return result + filter[0] * I[r][c].B;
482 template <
typename FilterType>
484 const FilterType *filter,
unsigned int size)
490 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
492 result += filter[i] * (I[r][c + i] + I[r][c - i]);
494 result += filter[i] * (I[r][2 * I.
getWidth() - c - i - 1] + I[r][c - i]);
496 return result + filter[0] * I[r][c];
500 const double *filter,
unsigned int size)
506 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
508 result += filter[i] * (I[r][c + i].R + I[r][c - i].R);
510 result += filter[i] * (I[r][2 * I.
getWidth() - c - i - 1].R + I[r][c - i].R);
512 return result + filter[0] * I[r][c].R;
516 const double *filter,
unsigned int size)
522 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
524 result += filter[i] * (I[r][c + i].G + I[r][c - i].G);
526 result += filter[i] * (I[r][2 * I.
getWidth() - c - i - 1].G + I[r][c - i].G);
528 return result + filter[0] * I[r][c].G;
532 const double *filter,
unsigned int size)
538 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
540 result += filter[i] * (I[r][c + i].B + I[r][c - i].B);
542 result += filter[i] * (I[r][2 * I.
getWidth() - c - i - 1].B + I[r][c - i].B);
544 return result + filter[0] * I[r][c].B;
547 template <
typename FilterType>
549 const FilterType *filter,
unsigned int size)
555 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
556 result += filter[i] * (I[r][c + i] + I[r][c - i]);
558 return result + filter[0] * I[r][c];
561 template <
typename FilterType>
563 const FilterType *filter,
unsigned int size)
569 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
571 result += filter[i] * (I[r][c + i] + I[r][c - i]);
573 result += filter[i] * (I[r][c + i] + I[r][i - c]);
575 return result + filter[0] * I[r][c];
578 template <
typename FilterType>
580 const FilterType *filter,
unsigned int size)
586 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
588 result += filter[i] * (I[r][c + i] + I[r][c - i]);
590 result += filter[i] * (I[r][2 * I.
getWidth() - c - i - 1] + I[r][c - i]);
592 return result + filter[0] * I[r][c];
595 template <
typename FilterType>
599 for (
unsigned int i = 0; i < (size - 1) / 2; i++) {
600 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
601 dIy[i][j] = vpImageFilter::filterYTopBorder<FilterType>(I, i, j, filter, size);
604 for (
unsigned int i = (size - 1) / 2; i < I.
getHeight() - (size - 1) / 2; i++) {
605 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
606 dIy[i][j] = vpImageFilter::filterY<FilterType>(I, i, j, filter, size);
610 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
611 dIy[i][j] = vpImageFilter::filterYBottomBorder<FilterType>(I, i, j, filter, size);
621 template<
typename FilterType>
625 for (
unsigned int i = 0; i < (size - 1) / 2; i++) {
626 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
627 dIy[i][j] = vpImageFilter::filterYTopBorder<FilterType>(I, i, j, filter, size);
630 for (
unsigned int i = (size - 1) / 2; i < I.
getHeight() - (size - 1) / 2; i++) {
631 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
632 dIy[i][j] = vpImageFilter::filterY<FilterType>(I, i, j, filter, size);
636 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
637 dIy[i][j] = vpImageFilter::filterYBottomBorder<FilterType>(I, i, j, filter, size);
642 template<
typename FilterType>
649 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
650 result += filter[i] * (I[r + i][c] + I[r - i][c]);
652 return result + filter[0] * I[r][c];
655 static inline double filterYR(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
661 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
662 result += filter[i] * (I[r + i][c].R + I[r - i][c].R);
664 return result + filter[0] * I[r][c].R;
666 static inline double filterYG(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
672 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
673 result += filter[i] * (I[r + i][c].G + I[r - i][c].G);
675 return result + filter[0] * I[r][c].G;
678 static inline double filterYB(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
684 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
685 result += filter[i] * (I[r + i][c].B + I[r - i][c].B);
687 return result + filter[0] * I[r][c].B;
690 template<
typename FilterType>
692 const FilterType *filter,
unsigned int size)
698 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
700 result += filter[i] * (I[r + i][c] + I[r - i][c]);
702 result += filter[i] * (I[r + i][c] + I[i - r][c]);
704 return result + filter[0] * I[r][c];
713 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
715 result += filter[i] * (I[r + i][c].R + I[r - i][c].R);
717 result += filter[i] * (I[r + i][c].R + I[i - r][c].R);
719 return result + filter[0] * I[r][c].R;
728 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
730 result += filter[i] * (I[r + i][c].G + I[r - i][c].G);
732 result += filter[i] * (I[r + i][c].G + I[i - r][c].G);
734 return result + filter[0] * I[r][c].G;
743 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
745 result += filter[i] * (I[r + i][c].B + I[r - i][c].B);
747 result += filter[i] * (I[r + i][c].B + I[i - r][c].B);
749 return result + filter[0] * I[r][c].B;
752 template<
typename FilterType>
754 const FilterType *filter,
unsigned int size)
760 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
762 result += filter[i] * (I[r + i][c] + I[r - i][c]);
764 result += filter[i] * (I[2 * I.
getHeight() - r - i - 1][c] + I[r - i][c]);
766 return result + filter[0] * I[r][c];
770 const double *filter,
unsigned int size)
776 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
778 result += filter[i] * (I[r + i][c].R + I[r - i][c].R);
780 result += filter[i] * (I[2 * I.
getHeight() - r - i - 1][c].R + I[r - i][c].R);
782 return result + filter[0] * I[r][c].R;
786 const double *filter,
unsigned int size)
792 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
794 result += filter[i] * (I[r + i][c].G + I[r - i][c].G);
796 result += filter[i] * (I[2 * I.
getHeight() - r - i - 1][c].G + I[r - i][c].G);
798 return result + filter[0] * I[r][c].G;
802 const double *filter,
unsigned int size)
808 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
810 result += filter[i] * (I[r + i][c].B + I[r - i][c].B);
812 result += filter[i] * (I[2 * I.
getHeight() - r - i - 1][c].B + I[r - i][c].B);
814 return result + filter[0] * I[r][c].B;
817 template<
typename FilterType>
819 const FilterType *filter,
unsigned int size)
825 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
827 result += filter[i] * (I[r + i][c] + I[r - i][c]);
829 result += filter[i] * (I[r + i][c] + I[i - r][c]);
831 return result + filter[0] * I[r][c];
834 template<
typename FilterType>
836 const FilterType *filter,
unsigned int size)
842 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
844 result += filter[i] * (I[r + i][c] + I[r - i][c]);
846 result += filter[i] * (I[2 * I.
getHeight() - r - i - 1][c] + I[r - i][c]);
848 return result + filter[0] * I[r][c];
851 template<
typename FilterType>
853 const FilterType *filter,
unsigned int size)
859 for (
unsigned int i = 1; i <= (size - 1) / 2; i++) {
860 result += filter[i] * (I[r + i][c] + I[r - i][c]);
862 return result + filter[0] * I[r][c];
877 template <
typename FilterType>
880 FilterType *fg =
new FilterType[(size + 1) / 2];
881 vpImageFilter::getGaussianKernel<FilterType>(fg, size, sigma, normalize);
883 vpImageFilter::filterX<FilterType>(I, GIx, fg, size);
884 vpImageFilter::filterY<FilterType>(GIx, GI, fg, size);
903 template <
typename FilterType>
906 FilterType *fg =
new FilterType[(size + 1) / 2];
907 vpImageFilter::getGaussianKernel<FilterType>(fg, size, sigma, normalize);
909 vpImageFilter::filterX<FilterType>(I, GIx, fg, size);
910 vpImageFilter::filterY<FilterType>(GIx, GI, fg, size);
924 return (15.0 * fr[r][c] + 12.0 * (fr[r - 1][c] + fr[r][c - 1] + fr[r + 1][c] + fr[r][c + 1]) +
925 9.0 * (fr[r - 1][c - 1] + fr[r + 1][c - 1] + fr[r - 1][c + 1] + fr[r + 1][c + 1]) +
926 5.0 * (fr[r - 2][c] + fr[r][c - 2] + fr[r + 2][c] + fr[r][c + 2]) +
927 4.0 * (fr[r - 2][c + 1] + fr[r - 2][c - 1] + fr[r - 1][c - 2] + fr[r + 1][c - 2] + fr[r + 2][c - 1] +
928 fr[r + 2][c + 1] + fr[r - 1][c + 2] + fr[r + 1][c + 2]) +
929 2.0 * (fr[r - 2][c - 2] + fr[r + 2][c - 2] + fr[r - 2][c + 2] + fr[r + 2][c + 2])) / 159.0;
952 template<
typename FilterType>
953 static void getGaussianKernel(FilterType *filter,
unsigned int size, FilterType sigma = 0.,
bool normalize =
true)
959 sigma =
static_cast<FilterType
>((size - 1) / 6.0);
961 int middle = (int)(size - 1) / 2;
962 FilterType sigma2 =
static_cast<FilterType
>(
vpMath::sqr(sigma));
963 FilterType coef1 =
static_cast<FilterType
>(1. / (sigma * sqrt(2. * M_PI)));
964 FilterType _2_sigma2 =
static_cast<FilterType
>(2. * sigma2);
965 for (
int i = 0; i <= middle; i++) {
966 filter[i] = coef1 * exp(-(i * i) / _2_sigma2);
971 for (
int i = 1; i <= middle; i++) {
972 sum += 2 * filter[i];
976 for (
int i = 0; i <= middle; i++) {
977 filter[i] = filter[i] / sum;
996 template <
typename FilterType>
1003 sigma =
static_cast<FilterType
>((size - 1) / 6.0);
1005 int middle = (int)(size - 1) / 2;
1006 FilterType sigma2 =
static_cast<FilterType
>(
vpMath::sqr(sigma));
1007 FilterType coef_1 =
static_cast<FilterType
>(1. / (sigma * sqrt(2. * M_PI)));
1008 FilterType coef_1_over_2 = coef_1 /
static_cast<FilterType
>(2.);
1009 FilterType _2_coef_1 =
static_cast<FilterType
>(2.) * coef_1;
1010 FilterType _2_sigma2 =
static_cast<FilterType
>(2. * sigma2);
1012 for (
int i = 1; i <= middle; i++) {
1013 filter[i] = -coef_1_over_2 * (
static_cast<FilterType
>(exp(-((i + 1) * (i + 1)) / _2_sigma2)) -
static_cast<FilterType
>(exp(-((i - 1) * (i - 1)) / _2_sigma2)));
1018 for (
int i = 1; i <= middle; i++) {
1019 sum += _2_coef_1 *
static_cast<FilterType
>(exp(-(i * i) / _2_sigma2));
1023 for (
int i = 1; i <= middle; i++) {
1024 filter[i] = filter[i] / sum;
1030 template<
typename FilterType>
1035 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
1036 for (
unsigned int j = 0; j < 3; j++) {
1039 for (
unsigned int j = 3; j < I.
getWidth() - 3; j++) {
1048 template <
typename ImageType,
typename FilterType>
1052 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
1053 for (
unsigned int j = 0; j < (size - 1) / 2; j++) {
1056 for (
unsigned int j = (size - 1) / 2; j < I.
getWidth() - (size - 1) / 2; j++) {
1057 dIx[i][j] = vpImageFilter::derivativeFilterX<ImageType, FilterType>(I, i, j, filter, size);
1059 for (
unsigned int j = I.
getWidth() - (size - 1) / 2; j < I.
getWidth(); j++) {
1075 template <
typename ImageType,
typename FilterType>
1077 const FilterType *gaussianDerivativeKernel,
unsigned int size)
1080 vpImageFilter::filterY<FilterType>(I, GIy, gaussianKernel, size);
1081 vpImageFilter::getGradX<FilterType, FilterType>(GIy, dIx, gaussianDerivativeKernel, size);
1085 template <
typename FilterType>
1089 for (
unsigned int i = 0; i < 3; i++) {
1090 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
1094 for (
unsigned int i = 3; i < I.
getHeight() - 3; i++) {
1095 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
1100 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
1106 template <
typename ImageType,
typename FilterType>
1110 for (
unsigned int i = 0; i < (size - 1) / 2; i++) {
1111 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
1115 for (
unsigned int i = (size - 1) / 2; i < I.
getHeight() - (size - 1) / 2; i++) {
1116 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
1117 dIy[i][j] = vpImageFilter::derivativeFilterY<ImageType, FilterType>(I, i, j, filter, size);
1121 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
1137 template <
typename ImageType,
typename FilterType>
1139 const FilterType *gaussianDerivativeKernel,
unsigned int size)
1142 vpImageFilter::filterX<FilterType>(I, GIx, gaussianKernel, size);
1143 vpImageFilter::getGradY<FilterType, FilterType>(GIx, dIy, gaussianDerivativeKernel, size);
1153 template <
typename FilterType>
1162 FilterType norm = getSobelKernelY<FilterType>(SobelY.
data, size);
1163 memcpy(filter, SobelY.
t().data, SobelY.
getRows() * SobelY.
getCols() *
sizeof(FilterType));
1174 template <
typename FilterType>
1178 static const FilterType SobelY3x3[9] = { -1.0, -2.0, -1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0 };
1179 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,
1180 0.0, 0.0, 2.0, 8.0, 12.0, 8.0, 2.0, 1.0, 4.0, 6.0, 4.0, 1.0 };
1181 static const FilterType SobelY7x7[49] = { -1, -6, -15, -20, -15, -6, -1, -4, -24, -60, -80, -60, -24, -4, -5, -30, -75,
1182 -100, -75, -30, -5, 0, 0, 0, 0, 0, 0, 0, 5, 30, 75, 100, 75, 30,
1183 5, 4, 24, 60, 80, 60, 24, 4, 1, 6, 15, 20, 15, 6, 1 };
1185 smoothingKernel[0][0] = 1.0;
1186 smoothingKernel[0][1] = 2.0;
1187 smoothingKernel[0][2] = 1.0;
1188 smoothingKernel[1][0] = 2.0;
1189 smoothingKernel[1][1] = 4.0;
1190 smoothingKernel[1][2] = 2.0;
1191 smoothingKernel[2][0] = 1.0;
1192 smoothingKernel[2][1] = 2.0;
1193 smoothingKernel[2][2] = 1.0;
1200 const unsigned int kernel_size = size * 2 + 1;
1201 if (kernel_size == 3) {
1202 memcpy(filter, SobelY3x3, kernel_size * kernel_size *
sizeof(FilterType));
1205 if (kernel_size == 5) {
1206 memcpy(filter, SobelY5x5, kernel_size * kernel_size *
sizeof(FilterType));
1209 if (kernel_size == 7) {
1210 memcpy(filter, SobelY7x7, kernel_size * kernel_size *
sizeof(FilterType));
1215 memcpy(sobelY.
data, SobelY7x7, sobelY.
getRows() * sobelY.
getCols() *
sizeof(FilterType));
1216 for (
unsigned int i = 4; i <= size; i++) {
1220 memcpy(filter, sobelY.
data, sobelY.
getRows() * sobelY.
getCols() *
sizeof(FilterType));
1225 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC)
1226 static float computeCannyThreshold(
const cv::Mat &cv_I,
const cv::Mat *p_cv_blur,
float &lowerThresh);
1228 static float median(
const cv::Mat &cv_I);
Implementation of a generic 2D array used as base class for matrices and vectors.
unsigned int getCols() const
Type * data
Address of the first element of the data array.
static vpArray2D< Type > conv2(const vpArray2D< Type > &M, const vpArray2D< Type > &kernel, const std::string &mode)
vpArray2D< Type > t() const
Compute the transpose of the array.
unsigned int getRows() const
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Error that can be emitted by the vpImage class and its derivatives.
@ incorrectInitializationError
Wrong image initialization.
Various image filter, convolution, etc...
static unsigned char filterGaussXPyramidal(const vpImage< unsigned char > &I, unsigned int i, unsigned int j)
static double filterXG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static double derivativeFilterY(const vpImage< T > &I, unsigned int r, unsigned int c)
static double filterYTopBorderG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void filterYB(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static double filterYBottomBorderB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static FilterType filterXLeftBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static void gaussianBlur(const vpImage< FilterType > &I, vpImage< FilterType > &GI, unsigned int size=7, FilterType sigma=0., bool normalize=true)
static void filterX(const vpImage< unsigned char > &I, vpImage< FilterType > &dIx, const FilterType *filter, unsigned int size)
static void getGradYGauss2D(const vpImage< ImageType > &I, vpImage< FilterType > &dIy, const FilterType *gaussianKernel, const FilterType *gaussianDerivativeKernel, unsigned int size)
static FilterType getSobelKernelX(FilterType *filter, unsigned int size)
static double filterXRightBorderB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static double filterYBottomBorderR(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static double filterYTopBorderB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void filterXB(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static double filterYR(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static FilterType filterY(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static void filter(const vpImage< FilterType > &I, vpImage< FilterType > &Iu, vpImage< FilterType > &Iv, const vpArray2D< FilterType > &M, bool convolve=false)
static void getGradXGauss2D(const vpImage< ImageType > &I, vpImage< FilterType > &dIx, const FilterType *gaussianKernel, const FilterType *gaussianDerivativeKernel, unsigned int size)
static FilterType filterX(const vpImage< FilterType > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static double filterXLeftBorderB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void filterYR(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static void gaussianBlur(const vpImage< unsigned char > &I, vpImage< FilterType > &GI, unsigned int size=7, FilterType sigma=0., bool normalize=true)
static double filterXB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static double filterXR(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static FilterType filterX(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static void getGaussianDerivativeKernel(FilterType *filter, unsigned int size, FilterType sigma=0., bool normalize=true)
static double derivativeFilterX(const vpImage< T > &I, unsigned int r, unsigned int c)
static double filterXLeftBorderR(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static FilterType filterYBottomBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static double filterXLeftBorderG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static double filterXRightBorderR(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void getGradX(const vpImage< unsigned char > &I, vpImage< FilterType > &dIx)
static FilterType filterXRightBorder(const vpImage< FilterType > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static FilterType derivativeFilterX(const vpImage< T > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static void filterXR(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static void getGaussianKernel(FilterType *filter, unsigned int size, FilterType sigma=0., bool normalize=true)
static double filterYTopBorderR(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void getGradX(const vpImage< ImageType > &I, vpImage< FilterType > &dIx, const FilterType *filter, unsigned int size)
static void filterYG(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static FilterType filterXLeftBorder(const vpImage< FilterType > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static double filterXRightBorderG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void filterY(const vpImage< FilterType > &I, vpImage< FilterType > &dIy, const FilterType *filter, unsigned int size)
static FilterType getSobelKernelY(FilterType *filter, unsigned int size)
static void getGradY(const vpImage< ImageType > &I, vpImage< FilterType > &dIy, const FilterType *filter, unsigned int size)
static FilterType filterY(const vpImage< double > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static void filterY(const vpImage< unsigned char > &I, vpImage< FilterType > &dIy, const FilterType *filter, unsigned int size)
static void filter(const vpImage< unsigned char > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false)
static FilterType derivativeFilterY(const vpImage< T > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static void filterX(const vpImage< FilterType > &I, vpImage< FilterType > &dIx, const FilterType *filter, unsigned int size)
static void filterXG(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static FilterType filterXRightBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static double filterYG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static FilterType filterYTopBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static FilterType filterYTopBorder(const vpImage< double > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static double filterYBottomBorderG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static double filterYB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static unsigned char filterGaussYPyramidal(const vpImage< unsigned char > &I, unsigned int i, unsigned int j)
static FilterType filterYBottomBorder(const vpImage< double > &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size)
static double gaussianFilter(const vpImage< T > &fr, unsigned int r, unsigned int c)
static void filter(const vpImage< unsigned char > &I, vpImage< FilterType > &GI, const FilterType *filter, unsigned int size)
static void filter(const vpImage< FilterType > &I, vpImage< FilterType > &GI, const FilterType *filter, unsigned int size)
static void getGradY(const vpImage< unsigned char > &I, vpImage< FilterType > &dIy)
void destroy()
Destructor : Memory de-allocation.
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getHeight() const
static double sqr(double x)