38 #include <visp3/core/vpImageFilter.h>
39 #include <visp3/core/vpImageConvert.h>
40 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408)
41 # include <opencv2/imgproc/imgproc.hpp>
42 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020101)
43 # include <opencv2/imgproc/imgproc_c.h>
44 #elif defined(VISP_HAVE_OPENCV)
78 const bool convolve) {
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;
132 const bool convolve) {
133 unsigned int size = M.
getRows();
134 unsigned int half_size = size/2;
140 for (
unsigned int v = half_size ; v < I.
getHeight()-half_size ; v++) {
141 for (
unsigned int u = half_size ; u < I.
getWidth()-half_size ; u++) {
145 for(
unsigned int a = 0 ; a < size ; a++ ) {
146 for(
unsigned int b = 0 ; b < size ; b++ ) {
147 double val = I[v+half_size-a][u+half_size-b];
148 conv_u += M[a][b] * val;
149 conv_v += M[b][a] * val;
157 for (
unsigned int v = half_size ; v < I.
getHeight()-half_size ; v++) {
158 for (
unsigned int u = half_size ; u < I.
getWidth()-half_size ; u++) {
162 for(
unsigned int a = 0 ; a < size ; a++ ) {
163 for(
unsigned int b = 0 ; b < size ; b++ ) {
164 double val = I[v-half_size+a][u-half_size+b];
165 conv_u += M[a][b] * val;
166 conv_v += M[b][a] * val;
231 unsigned int size = kernelH.
size();
232 unsigned int half_size = size/2;
237 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
238 for (
unsigned int j = half_size; j < I.
getWidth()-half_size; j++) {
240 for (
unsigned int a = 0; a < kernelH.
size(); a++) {
241 conv += kernelH[a] * I[i][j+half_size-a];
244 I_filter[i][j] = conv;
248 for (
unsigned int i = half_size; i < I.
getHeight()-half_size; i++) {
249 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
251 for (
unsigned int a = 0; a < kernelV.
size(); a++) {
252 conv += kernelV[a] * I_filter[i+half_size-a][j];
260 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
304 const unsigned int gaussianFilterSize,
305 const double thresholdCanny,
306 const unsigned int apertureSobel)
308 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
309 IplImage* img_ipl = NULL;
312 edges_ipl = cvCreateImage(cvSize(img_ipl->width, img_ipl->height), img_ipl->depth, img_ipl->nChannels);
314 cvSmooth(img_ipl, img_ipl, CV_GAUSSIAN, (
int)gaussianFilterSize, (
int)gaussianFilterSize, 0, 0);
315 cvCanny(img_ipl, edges_ipl, thresholdCanny, thresholdCanny, (
int)apertureSobel);
318 cvReleaseImage(&img_ipl);
319 cvReleaseImage(&edges_ipl);
321 cv::Mat img_cvmat, edges_cvmat;
323 cv::GaussianBlur(img_cvmat, img_cvmat, cv::Size((
int)gaussianFilterSize, (
int)gaussianFilterSize), 0, 0);
324 cv::Canny(img_cvmat, edges_cvmat, thresholdCanny, thresholdCanny, (
int)apertureSobel);
355 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
357 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
362 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
376 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
378 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
383 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
397 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
399 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
404 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
406 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
413 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
422 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
424 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
429 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
431 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
438 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
456 double *fg=
new double[(size+1)/2] ;
476 double *fg=
new double[(size+1)/2] ;
498 "Bad Gaussian filter size"));
501 sigma = (size-1)/6.0;
503 int middle = (int)(size-1)/2;
505 for(
int i=0; i<= middle; i++)
507 filter[i] = (1./(sigma*sqrt(2.*M_PI)))*exp(-(i*i)/(2.*sigma2));
512 for(
int i=1; i<=middle; i++)
518 for(
int i=0; i<=middle; i++)
520 filter[i] = filter[i]/sum;
538 "Bad Gaussian filter size"));
541 sigma = (size-1)/6.0;
543 int middle = (int)(size-1)/2;
546 for(
int i=1; i<= middle; i++)
548 filter[i] = -(1./(sigma*sqrt(2.*M_PI)))*(exp(-((i+1)*(i+1))/(2.*sigma2))-exp(-((i-1)*(i-1))/(2.*sigma2)))/2.;
553 for(
int i=1; i<=middle; i++)
555 sum += 2.*(1./(sigma*sqrt(2.*M_PI)))*exp(-(i*i)/(2.*sigma2));
557 sum += (1./(sigma*sqrt(2.*M_PI))) ;
559 for(
int i=1; i<=middle; i++)
561 filter[i] = filter[i]/sum;
571 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
573 for (
unsigned int j=0 ; j < 3 ; j++)
577 for (
unsigned int j=3 ; j < I.
getWidth()-3 ; j++)
592 for (
unsigned int i=0 ; i < 3 ; i++)
594 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
599 for (
unsigned int i=3 ; i < I.
getHeight()-3 ; i++)
601 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
608 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
619 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
621 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
625 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
639 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
641 for (
unsigned int j=0 ; j < (size-1)/2 ; j++)
645 for (
unsigned int j=(size-1)/2 ; j < I.
getWidth()-(size-1)/2 ; j++)
660 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
662 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
668 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
670 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
678 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
689 for (
unsigned int i=0 ; i < (size-1)/2 ; i++)
691 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
696 for (
unsigned int i=(size-1)/2 ; i < I.
getHeight()-(size-1)/2 ; i++)
698 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
705 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
746 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
747 cv::Mat imgsrc, imgdest;
749 cv::pyrDown( imgsrc, imgdest, cv::Size((
int)I.
getWidth()/2,(int)I.
getHeight()/2));
751 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408)
752 cv::Mat imgsrc, imgdest;
756 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
757 IplImage* imgsrc = NULL;
758 IplImage* imgdest = NULL;
759 imgsrc = cvCreateImage(cvSize((
int)I.
getWidth(),(int)I.
getHeight()), IPL_DEPTH_8U, 1);
760 imgdest = cvCreateImage(cvSize((
int)I.
getWidth()/2,(int)I.
getHeight()/2), IPL_DEPTH_8U, 1);
762 cvPyrDown( imgsrc, imgdest);
765 cvReleaseImage(&imgsrc);
766 cvReleaseImage(&imgdest);
779 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
782 for (
unsigned int j=1 ; j < ((I.
getWidth()+1.)/2.)-1 ; j++)
786 GI[i][(int)((I.
getWidth()+1.)/2.)-1]=I[i][2*((int)((I.
getWidth()+1.)/2.)-1)];
792 for (
unsigned int i=0 ; i < I.
getHeight() ; i++)
795 for (
unsigned int j=1 ; j < w-1 ; j++)
799 GI[i][w-1]=I[i][2*w-1];
809 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
812 for (
unsigned int i=1 ; i < ((I.
getHeight()+1.)/2.)-1 ; i++)
823 for (
unsigned int j=0 ; j < I.
getWidth() ; j++)
826 for (
unsigned int i=1 ; i < h-1 ; i++)
830 GI[h-1][j]=I[2*h-1][j];
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)
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 sepFilter(const vpImage< unsigned char > &I, vpImage< double > &If, const vpColVector &kernelH, const vpColVector &kernelV)
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)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
Return the number of columns of the 2D array.
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 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)
resize the image : Image initialization
unsigned int getRows() const
Return the number of rows of the 2D array.
void destroy()
Destructor : Memory de-allocation.
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)
Implementation of column vector and the associated operations.
static unsigned char filterGaussXPyramidal(const vpImage< unsigned char > &I, unsigned int i, unsigned int j)
unsigned int getHeight() const
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, const bool convolve=false)
static void canny(const vpImage< unsigned char > &I, vpImage< unsigned char > &Ic, const unsigned int gaussianFilterSize, const double thresholdCanny, const unsigned int apertureSobel)
static double derivativeFilterX(const vpImage< T > &I, const unsigned int r, const unsigned int c)