42 #include <visp/vpImageFilter.h>
43 #include <visp/vpImageConvert.h>
44 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020101)
45 #include <opencv2/imgproc/imgproc_c.h>
46 #elif defined(VISP_HAVE_OPENCV)
64 unsigned int size = M.
getRows() ;
65 unsigned int half_size = size/2 ;
71 for (
unsigned int i=half_size ; i < I.
getHeight()-half_size ; i++)
73 for (
unsigned int j=half_size ; j < I.
getWidth()-half_size ; j++)
77 for(
unsigned int a = 0 ; a < size ; a++ )
78 for(
unsigned int b = 0 ; b < size ; b++ )
80 double val = I[i-half_size+a][j-half_size+b] ;
81 conv_x += M[a][b] * val ;
105 unsigned int size = M.
getRows() ;
106 unsigned int half_size = size/2 ;
113 for (
unsigned int v=half_size ; v < I.
getHeight()-half_size ; v++)
115 for (
unsigned int u=half_size ; u < I.
getWidth()-half_size ; u++)
120 for(
unsigned int a = 0 ; a < size ; a++ )
121 for(
unsigned int b = 0 ; b < size ; b++ )
123 double val = I[v-half_size+a][u-half_size+b] ;
124 conv_u += M[a][b] * val ;
125 conv_v += M[b][a] * val ;
134 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
178 const unsigned int gaussianFilterSize,
179 const double thresholdCanny,
180 const unsigned int apertureSobel)
182 IplImage* img_ipl = NULL;
185 edges_ipl = cvCreateImage(cvSize(img_ipl->width, img_ipl->height), img_ipl->depth, img_ipl->nChannels);
187 cvSmooth(img_ipl, img_ipl, CV_GAUSSIAN, (
int)gaussianFilterSize, (
int)gaussianFilterSize, 0, 0);
188 cvCanny(img_ipl, edges_ipl, thresholdCanny, thresholdCanny, (
int)apertureSobel);
191 cvReleaseImage(&img_ipl);
192 cvReleaseImage(&edges_ipl);
221 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
223 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
228 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
242 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
244 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
249 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
263 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
265 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
270 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
272 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
279 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
288 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
290 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
295 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
297 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
304 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
322 double *fg=
new double[(size+1)/2] ;
344 "Bad Gaussian filter size"));
347 sigma = (size-1)/6.0;
349 int middle = (int)(size-1)/2;
351 for(
int i=0; i<= middle; i++)
353 filter[i] = (1./(sigma*sqrt(2.*M_PI)))*exp(-(i*i)/(2.*sigma2));
358 for(
int i=1; i<=middle; i++)
364 for(
int i=0; i<=middle; i++)
366 filter[i] = filter[i]/sum;
384 "Bad Gaussian filter size"));
387 sigma = (size-1)/6.0;
389 int middle = (int)(size-1)/2;
392 for(
int i=1; i<= middle; i++)
394 filter[i] = -(1./(sigma*sqrt(2.*M_PI)))*(exp(-((i+1)*(i+1))/(2.*sigma2))-exp(-((i-1)*(i-1))/(2.*sigma2)))/2.;
399 for(
int i=1; i<=middle; i++)
401 sum += 2.*(1./(sigma*sqrt(2.*M_PI)))*exp(-(i*i)/(2.*sigma2));
403 sum += (1./(sigma*sqrt(2.*M_PI))) ;
405 for(
int i=1; i<=middle; i++)
407 filter[i] = filter[i]/sum;
417 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
419 for (
unsigned int j=0 ; j < 3 ; j++)
423 for (
unsigned int j=3 ; j < I.
getWidth()-3 ; j++)
438 for (
unsigned int i=0 ; i < 3 ; i++)
440 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
445 for (
unsigned int i=3 ; i < I.
getHeight()-3 ; i++)
447 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
454 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
465 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
467 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
471 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
485 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
487 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
491 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
506 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
508 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
514 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
516 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
524 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
535 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
537 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
542 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
544 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
551 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
592 #ifdef VISP_HAVE_OPENCV
593 IplImage* imgsrc = NULL;
594 IplImage* imgdest = NULL;
595 imgsrc = cvCreateImage(cvSize((
int)I.
getWidth(),(int)I.
getHeight()), IPL_DEPTH_8U, 1);
596 imgdest = cvCreateImage(cvSize((
int)I.
getWidth()/2,(int)I.
getHeight()/2), IPL_DEPTH_8U, 1);
598 cvPyrDown( imgsrc, imgdest);
601 cvReleaseImage(&imgsrc);
602 cvReleaseImage(&imgdest);
615 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
618 for (
unsigned int j=1 ; j < ((I.
getWidth()+1.)/2.)-1 ; j++)
622 GI[i][(int)((I.
getWidth()+1.)/2.)-1]=I[i][2*((int)((I.
getWidth()+1.)/2.)-1)];
628 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
631 for (
unsigned int j=1 ; j < w-1 ; j++)
635 GI[i][w-1]=I[i][2*w-1];
645 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
648 for (
unsigned int i=1 ; i < ((I.
getHeight()+1.)/2.)-1 ; i++)
659 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
662 for (
unsigned int i=1 ; i < h-1 ; i++)
666 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
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)