39 #include <visp3/core/vpImageConvert.h> 40 #include <visp3/core/vpImageFilter.h> 41 #include <visp3/core/vpRGBa.h> 42 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408) 43 #include <opencv2/imgproc/imgproc.hpp> 44 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020101) 45 #include <opencv2/imgproc/imgproc_c.h> 46 #elif defined(VISP_HAVE_OPENCV) 80 unsigned int half_size_y = size_y / 2, half_size_x = size_x / 2;
85 for (
unsigned int i = half_size_y; i < I.
getHeight() - half_size_y; i++) {
86 for (
unsigned int j = half_size_x; j < I.
getWidth() - half_size_x; j++) {
89 for (
unsigned int a = 0; a < size_y; a++) {
90 for (
unsigned int b = 0; b < size_x; b++) {
91 double val = I[i + half_size_y - a][j + half_size_x - b];
92 conv += M[a][b] * val;
99 for (
unsigned int i = half_size_y; i < I.
getHeight() - half_size_y; i++) {
100 for (
unsigned int j = half_size_x; j < I.
getWidth() - half_size_x; j++) {
103 for (
unsigned int a = 0; a < size_y; a++) {
104 for (
unsigned int b = 0; b < size_x; b++) {
105 double val = I[i - half_size_y + a][j - half_size_x + b];
106 corr += M[a][b] * val;
130 unsigned int size = M.
getRows();
131 unsigned int half_size = size / 2;
137 for (
unsigned int v = half_size; v < I.
getHeight() - half_size; v++) {
138 for (
unsigned int u = half_size; u < I.
getWidth() - half_size; u++) {
142 for (
unsigned int a = 0; a < size; a++) {
143 for (
unsigned int b = 0; b < size; b++) {
144 double val = I[v + half_size - a][u + half_size - b];
145 conv_u += M[a][b] * val;
146 conv_v += M[b][a] * val;
154 for (
unsigned int v = half_size; v < I.
getHeight() - half_size; v++) {
155 for (
unsigned int u = half_size; u < I.
getWidth() - half_size; u++) {
159 for (
unsigned int a = 0; a < size; a++) {
160 for (
unsigned int b = 0; b < size; b++) {
161 double val = I[v - half_size + a][u - half_size + b];
162 conv_u += M[a][b] * val;
163 conv_v += M[b][a] * val;
228 unsigned int size = kernelH.
size();
229 unsigned int half_size = size / 2;
234 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
235 for (
unsigned int j = half_size; j < I.
getWidth() - half_size; j++) {
237 for (
unsigned int a = 0; a < kernelH.
size(); a++) {
238 conv += kernelH[a] * I[i][j + half_size - a];
241 I_filter[i][j] = conv;
245 for (
unsigned int i = half_size; i < I.
getHeight() - half_size; i++) {
246 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
248 for (
unsigned int a = 0; a < kernelV.
size(); a++) {
249 conv += kernelV[a] * I_filter[i + half_size - a][j];
257 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) 299 unsigned int gaussianFilterSize,
double thresholdCanny,
300 unsigned int apertureSobel)
302 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 303 IplImage *img_ipl = NULL;
306 edges_ipl = cvCreateImage(cvSize(img_ipl->width, img_ipl->height), img_ipl->depth, img_ipl->nChannels);
308 cvSmooth(img_ipl, img_ipl, CV_GAUSSIAN, (
int)gaussianFilterSize, (
int)gaussianFilterSize, 0, 0);
309 cvCanny(img_ipl, edges_ipl, thresholdCanny, thresholdCanny, (
int)apertureSobel);
312 cvReleaseImage(&img_ipl);
313 cvReleaseImage(&edges_ipl);
315 cv::Mat img_cvmat, edges_cvmat;
317 cv::GaussianBlur(img_cvmat, img_cvmat, cv::Size((
int)gaussianFilterSize, (
int)gaussianFilterSize), 0, 0);
318 cv::Canny(img_cvmat, edges_cvmat, thresholdCanny, thresholdCanny, (
int)apertureSobel);
332 filterY(GIx, GI, filter, size);
343 filterY(GIx, GI, filter, size);
351 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
352 for (
unsigned int j = 0; j < (size - 1) / 2; j++) {
356 for (
unsigned int j = (size - 1) / 2; j < I.
getWidth() - (size - 1) / 2; j++) {
359 for (
unsigned int j = I.
getWidth() - (size - 1) / 2; j < I.
getWidth(); j++) {
369 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
370 for (
unsigned int j = 0; j < (size - 1) / 2; j++) {
375 for (
unsigned int j = (size - 1) / 2; j < I.
getWidth() - (size - 1) / 2; j++) {
380 for (
unsigned int j = I.
getWidth() - (size - 1) / 2; j < I.
getWidth(); j++) {
390 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
391 for (
unsigned int j = 0; j < (size - 1) / 2; j++) {
395 for (
unsigned int j = (size - 1) / 2; j < I.
getWidth() - (size - 1) / 2; j++) {
398 for (
unsigned int j = I.
getWidth() - (size - 1) / 2; j < I.
getWidth(); j++) {
408 for (
unsigned int i = 0; i < (size - 1) / 2; i++) {
409 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
413 for (
unsigned int i = (size - 1) / 2; i < I.
getHeight() - (size - 1) / 2; i++) {
414 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
419 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
428 for (
unsigned int i = 0; i < (size - 1) / 2; i++) {
429 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
435 for (
unsigned int i = (size - 1) / 2; i < I.
getHeight() - (size - 1) / 2; i++) {
436 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
443 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
453 for (
unsigned int i = 0; i < (size - 1) / 2; i++) {
454 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
458 for (
unsigned int i = (size - 1) / 2; i < I.
getHeight() - (size - 1) / 2; i++) {
459 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
464 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
485 double *fg =
new double[(size + 1) / 2];
508 double *fg =
new double[(size + 1) / 2];
531 double *fg =
new double[(size + 1) / 2];
561 sigma = (size - 1) / 6.0;
563 int middle = (int)(size - 1) / 2;
565 for (
int i = 0; i <= middle; i++) {
566 filter[i] = (1. / (sigma * sqrt(2. * M_PI))) * exp(-(i * i) / (2. * sigma2));
571 for (
int i = 1; i <= middle; i++) {
572 sum += 2 * filter[i];
576 for (
int i = 0; i <= middle; i++) {
577 filter[i] = filter[i] / sum;
601 sigma = (size - 1) / 6.0;
603 int middle = (int)(size - 1) / 2;
606 for (
int i = 1; i <= middle; i++) {
607 filter[i] = -(1. / (sigma * sqrt(2. * M_PI))) *
608 (exp(-((i + 1) * (i + 1)) / (2. * sigma2)) - exp(-((i - 1) * (i - 1)) / (2. * sigma2))) / 2.;
613 for (
int i = 1; i <= middle; i++) {
614 sum += 2. * (1. / (sigma * sqrt(2. * M_PI))) * exp(-(i * i) / (2. * sigma2));
616 sum += (1. / (sigma * sqrt(2. * M_PI)));
618 for (
int i = 1; i <= middle; i++) {
619 filter[i] = filter[i] / sum;
628 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
629 for (
unsigned int j = 0; j < 3; j++) {
632 for (
unsigned int j = 3; j < I.
getWidth() - 3; j++) {
645 for (
unsigned int i = 0; i < 3; i++) {
646 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
650 for (
unsigned int i = 3; i < I.
getHeight() - 3; i++) {
651 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
656 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
667 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
668 for (
unsigned int j = 0; j < (size - 1) / 2; j++) {
671 for (
unsigned int j = (size - 1) / 2; j < I.
getWidth() - (size - 1) / 2; j++) {
674 for (
unsigned int j = I.
getWidth() - (size - 1) / 2; j < I.
getWidth(); j++) {
683 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
684 for (
unsigned int j = 0; j < (size - 1) / 2; j++) {
687 for (
unsigned int j = (size - 1) / 2; j < I.
getWidth() - (size - 1) / 2; j++) {
690 for (
unsigned int j = I.
getWidth() - (size - 1) / 2; j < I.
getWidth(); j++) {
701 for (
unsigned int i = 0; i < (size - 1) / 2; i++) {
702 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
707 for (
unsigned int i = (size - 1) / 2; i < I.
getHeight() - (size - 1) / 2; i++) {
708 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
714 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
724 for (
unsigned int i = 0; i < (size - 1) / 2; i++) {
725 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
729 for (
unsigned int i = (size - 1) / 2; i < I.
getHeight() - (size - 1) / 2; i++) {
730 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
735 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
751 const double *gaussianDerivativeKernel,
unsigned int size)
768 const double *gaussianDerivativeKernel,
unsigned int size)
779 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000) 780 cv::Mat imgsrc, imgdest;
782 cv::pyrDown(imgsrc, imgdest, cv::Size((
int)I.
getWidth() / 2, (int)I.
getHeight() / 2));
784 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408) 785 cv::Mat imgsrc, imgdest;
787 cv::pyrDown(imgsrc, imgdest, cvSize((
int)I.
getWidth() / 2, (int)I.
getHeight() / 2));
789 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) 790 IplImage *imgsrc = NULL;
791 IplImage *imgdest = NULL;
792 imgsrc = cvCreateImage(cvSize((
int)I.
getWidth(), (int)I.
getHeight()), IPL_DEPTH_8U, 1);
793 imgdest = cvCreateImage(cvSize((
int)I.
getWidth() / 2, (int)I.
getHeight() / 2), IPL_DEPTH_8U, 1);
795 cvPyrDown(imgsrc, imgdest);
798 cvReleaseImage(&imgsrc);
799 cvReleaseImage(&imgdest);
812 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
815 for (
unsigned int j=1 ; j < ((I.
getWidth()+1.)/2.)-1 ; j++)
819 GI[i][(int)((I.
getWidth()+1.)/2.)-1]=I[i][2*((int)((I.
getWidth()+1.)/2.)-1)];
825 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
827 for (
unsigned int j = 1; j < w - 1; j++) {
830 GI[i][w - 1] = I[i][2 * w - 1];
840 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
842 for (
unsigned int i = 1; i < ((I.
getHeight() + 1.) / 2.) - 1; i++) {
845 GI[(int)((I.
getHeight() + 1.) / 2.) - 1][j] = I[2 * ((int)((I.
getHeight() + 1.) / 2.) - 1)][j];
852 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
854 for (
unsigned int i = 1; i < h - 1; i++) {
857 GI[h - 1][j] = I[2 * h - 1][j];
876 vpMatrix SobelY(size*2+1, size*2+1);
892 static const double SobelY3x3[9] = {-1.0, -2.0, -1.0,
895 static const double SobelY5x5[25] = {-1.0, -4.0, -6.0, -4.0, -1.0,
896 -2.0, -8.0, -12.0, -8.0, -2.0,
897 0.0, 0.0, 0.0, 0.0, 0.0,
898 2.0, 8.0, 12.0, 8.0, 2.0,
899 1.0, 4.0, 6.0, 4.0, 1.0};
900 static const double SobelY7x7[49] = {-1, -6, -15, -20, -15, -6, -1,
901 -4, -24, -60, -80, -60, -24, -4,
902 -5, -30, -75, -100, -75, -30, -5,
904 5, 30, 75, 100, 75, 30, 5,
905 4, 24, 60, 80, 60, 24, 4,
906 1, 6, 15, 20, 15, 6, 1};
907 static const vpMatrix smoothingKernel(3,3);
908 smoothingKernel[0][0] = 1.0; smoothingKernel[0][1] = 2.0; smoothingKernel[0][2] = 1.0;
909 smoothingKernel[1][0] = 2.0; smoothingKernel[1][1] = 4.0; smoothingKernel[1][2] = 2.0;
910 smoothingKernel[2][0] = 1.0; smoothingKernel[2][1] = 2.0; smoothingKernel[2][2] = 1.0;
917 const unsigned int kernel_size = size*2+1;
918 if (kernel_size == 3) {
919 memcpy(filter, SobelY3x3, kernel_size*kernel_size*
sizeof(
double));
922 if (kernel_size == 5) {
923 memcpy(filter, SobelY5x5, kernel_size*kernel_size*
sizeof(
double));
926 if (kernel_size == 7) {
927 memcpy(filter, SobelY7x7, kernel_size*kernel_size*
sizeof(
double));
933 for (
unsigned int i = 4; i <= size; i++) {
static double getSobelKernelY(double *filter, unsigned int size)
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
Implementation of a matrix and operations on matrices.
static double filterXLeftBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void filterXR(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static double filterYTopBorderG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void filterYG(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static double filterYBottomBorderG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode="full")
static void filterXB(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static double derivativeFilterX(const vpImage< T > &I, unsigned int r, unsigned int c)
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
static void getGradX(const vpImage< unsigned char > &I, vpImage< double > &dIx)
static void filterYB(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static void getGaussYPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
static void getGradY(const vpImage< unsigned char > &I, vpImage< double > &dIy)
static void sepFilter(const vpImage< unsigned char > &I, vpImage< double > &If, const vpColVector &kernelH, const vpColVector &kernelV)
static double derivativeFilterY(const vpImage< T > &I, unsigned int r, unsigned int c)
static double filterYBottomBorderB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void getGaussianKernel(double *filter, unsigned int size, double sigma=0., bool normalize=true)
error that can be emited by ViSP classes.
static unsigned char filterGaussYPyramidal(const vpImage< unsigned char > &I, unsigned int i, unsigned int j)
Type * data
Address of the first element of the data array.
static void getGradYGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIy, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
static double filterXLeftBorderB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
Error that can be emited by the vpImage class and its derivates.
static void getGradXGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIx, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
static double filterYTopBorderR(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 filterY(const vpImage< unsigned char > &I, vpImage< double > &dIx, const double *filter, unsigned int size)
static void getGaussXPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
static double sqr(double x)
static double filterXRightBorderG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void canny(const vpImage< unsigned char > &I, vpImage< unsigned char > &Ic, unsigned int gaussianFilterSize, double thresholdCanny, unsigned int apertureSobel)
static void gaussianBlur(const vpImage< unsigned char > &I, vpImage< double > &GI, unsigned int size=7, double sigma=0., bool normalize=true)
static double filterYTopBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static double filterXRightBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
unsigned int getRows() const
static double filterXLeftBorderG(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
void destroy()
Destructor : Memory de-allocation.
static double filterXRightBorderB(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, bool convolve=false)
static void filterXG(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static void filterX(const vpImage< unsigned char > &I, vpImage< double > &dIx, const double *filter, unsigned int size)
static void getGaussianDerivativeKernel(double *filter, unsigned int size, double sigma=0., bool normalize=true)
static void filterYR(const vpImage< vpRGBa > &I, vpImage< vpRGBa > &dIx, const double *filter, unsigned int size)
static double filterYBottomBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
Implementation of column vector and the associated operations.
static unsigned char filterGaussXPyramidal(const vpImage< unsigned char > &I, unsigned int i, unsigned int j)
static double filterXLeftBorderR(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)
unsigned int getHeight() const
static double getSobelKernelX(double *filter, unsigned int size)
static double filterYBottomBorderR(const vpImage< vpRGBa > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)