42 #include <visp/vpImageFilter.h>
43 #include <visp/vpImageConvert.h>
44 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408)
45 # include <opencv2/imgproc/imgproc.hpp>
46 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020101)
47 # include <opencv2/imgproc/imgproc_c.h>
48 #elif defined(VISP_HAVE_OPENCV)
66 unsigned int size = M.
getRows() ;
67 unsigned int half_size = size/2 ;
73 for (
unsigned int i=half_size ; i < I.
getHeight()-half_size ; i++)
75 for (
unsigned int j=half_size ; j < I.
getWidth()-half_size ; j++)
79 for(
unsigned int a = 0 ; a < size ; a++ )
80 for(
unsigned int b = 0 ; b < size ; b++ )
82 double val = I[i-half_size+a][j-half_size+b] ;
83 conv_x += M[a][b] * val ;
107 unsigned int size = M.
getRows() ;
108 unsigned int half_size = size/2 ;
115 for (
unsigned int v=half_size ; v < I.
getHeight()-half_size ; v++)
117 for (
unsigned int u=half_size ; u < I.
getWidth()-half_size ; u++)
122 for(
unsigned int a = 0 ; a < size ; a++ )
123 for(
unsigned int b = 0 ; b < size ; b++ )
125 double val = I[v-half_size+a][u-half_size+b] ;
126 conv_u += M[a][b] * val ;
127 conv_v += M[b][a] * val ;
136 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
180 const unsigned int gaussianFilterSize,
181 const double thresholdCanny,
182 const unsigned int apertureSobel)
184 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
185 IplImage* img_ipl = NULL;
188 edges_ipl = cvCreateImage(cvSize(img_ipl->width, img_ipl->height), img_ipl->depth, img_ipl->nChannels);
190 cvSmooth(img_ipl, img_ipl, CV_GAUSSIAN, (
int)gaussianFilterSize, (
int)gaussianFilterSize, 0, 0);
191 cvCanny(img_ipl, edges_ipl, thresholdCanny, thresholdCanny, (
int)apertureSobel);
194 cvReleaseImage(&img_ipl);
195 cvReleaseImage(&edges_ipl);
197 cv::Mat img_cvmat, edges_cvmat;
199 cv::GaussianBlur(img_cvmat, img_cvmat, cv::Size((
int)gaussianFilterSize, (
int)gaussianFilterSize), 0, 0);
200 cv::Canny(img_cvmat, edges_cvmat, thresholdCanny, thresholdCanny, (
int)apertureSobel);
231 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
233 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
238 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
252 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
254 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
259 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
273 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
275 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
280 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
282 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
289 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
298 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
300 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
305 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
307 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
314 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
332 double *fg=
new double[(size+1)/2] ;
354 "Bad Gaussian filter size"));
357 sigma = (size-1)/6.0;
359 int middle = (int)(size-1)/2;
361 for(
int i=0; i<= middle; i++)
363 filter[i] = (1./(sigma*sqrt(2.*M_PI)))*exp(-(i*i)/(2.*sigma2));
368 for(
int i=1; i<=middle; i++)
374 for(
int i=0; i<=middle; i++)
376 filter[i] = filter[i]/sum;
394 "Bad Gaussian filter size"));
397 sigma = (size-1)/6.0;
399 int middle = (int)(size-1)/2;
402 for(
int i=1; i<= middle; i++)
404 filter[i] = -(1./(sigma*sqrt(2.*M_PI)))*(exp(-((i+1)*(i+1))/(2.*sigma2))-exp(-((i-1)*(i-1))/(2.*sigma2)))/2.;
409 for(
int i=1; i<=middle; i++)
411 sum += 2.*(1./(sigma*sqrt(2.*M_PI)))*exp(-(i*i)/(2.*sigma2));
413 sum += (1./(sigma*sqrt(2.*M_PI))) ;
415 for(
int i=1; i<=middle; i++)
417 filter[i] = filter[i]/sum;
427 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
429 for (
unsigned int j=0 ; j < 3 ; j++)
433 for (
unsigned int j=3 ; j < I.
getWidth()-3 ; j++)
448 for (
unsigned int i=0 ; i < 3 ; i++)
450 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
455 for (
unsigned int i=3 ; i < I.
getHeight()-3 ; i++)
457 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
464 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
475 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
477 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
481 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
495 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
497 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
501 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
516 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
518 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
524 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
526 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
534 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
545 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
547 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
552 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
554 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
561 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
602 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
603 cv::Mat imgsrc, imgdest;
605 cv::pyrDown( imgsrc, imgdest, cv::Size((
int)I.
getWidth()/2,(int)I.
getHeight()/2));
607 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408)
608 cv::Mat imgsrc, imgdest;
612 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
613 IplImage* imgsrc = NULL;
614 IplImage* imgdest = NULL;
615 imgsrc = cvCreateImage(cvSize((
int)I.
getWidth(),(int)I.
getHeight()), IPL_DEPTH_8U, 1);
616 imgdest = cvCreateImage(cvSize((
int)I.
getWidth()/2,(int)I.
getHeight()/2), IPL_DEPTH_8U, 1);
618 cvPyrDown( imgsrc, imgdest);
621 cvReleaseImage(&imgsrc);
622 cvReleaseImage(&imgdest);
635 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
638 for (
unsigned int j=1 ; j < ((I.
getWidth()+1.)/2.)-1 ; j++)
642 GI[i][(int)((I.
getWidth()+1.)/2.)-1]=I[i][2*((int)((I.
getWidth()+1.)/2.)-1)];
648 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
651 for (
unsigned int j=1 ; j < w-1 ; j++)
655 GI[i][w-1]=I[i][2*w-1];
665 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
668 for (
unsigned int i=1 ; i < ((I.
getHeight()+1.)/2.)-1 ; i++)
679 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
682 for (
unsigned int i=1 ; i < h-1 ; i++)
686 GI[h-1][j]=I[2*h-1][j];
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
Definition of the vpMatrix class.
static double filterXLeftBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void getGradX(const vpImage< unsigned char > &I, vpImage< double > &dIx)
static void getGaussYPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
static void getGradY(const vpImage< unsigned char > &I, vpImage< double > &dIy)
static double derivativeFilterY(const vpImage< T > &I, const unsigned int r, const unsigned int c)
static void getGaussianKernel(double *filter, unsigned int size, double sigma=0., bool normalize=true)
static unsigned char filterGaussYPyramidal(const vpImage< unsigned char > &I, unsigned int i, unsigned int j)
static void getGradYGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIy, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
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 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 void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M)
static double sqr(double x)
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)
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
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 double filterYBottomBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
static unsigned char filterGaussXPyramidal(const vpImage< unsigned char > &I, unsigned int i, unsigned int j)
unsigned int getHeight() const
static void canny(const vpImage< unsigned char > &I, vpImage< unsigned char > &Ic, const unsigned int gaussianFilterSize, const double thresholdCanny, const unsigned int apertureSobel)
unsigned int getRows() const
Return the number of rows of the matrix.
static double derivativeFilterX(const vpImage< T > &I, const unsigned int r, const unsigned int c)