Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpImageFilter.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Various image tools, convolution, ...
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
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)
45 # include <cv.h>
46 #endif
47 
48 
74 void
76  vpImage<double>& If,
77  const vpMatrix& M,
78  const bool convolve) {
79  unsigned int size_y = M.getRows(), size_x = M.getCols();
80  unsigned int half_size_y = size_y/2, half_size_x = size_x/2;
81 
82  If.resize(I.getHeight(),I.getWidth(), 0.0);
83 
84  if (convolve) {
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++) {
87  double conv = 0;
88 
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]; //Convolution
92  conv += M[a][b] * val;
93  }
94  }
95  If[i][j] = conv;
96  }
97  }
98  } else {
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++) {
101  double corr = 0;
102 
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]; //Correlation
106  corr += M[a][b] * val;
107  }
108  }
109  If[i][j] = corr;
110  }
111  }
112  }
113 }
114 
127 void
129  vpImage<double>& Iu,
130  vpImage<double>& Iv,
131  const vpMatrix& M,
132  const bool convolve) {
133  unsigned int size = M.getRows();
134  unsigned int half_size = size/2;
135 
136  Iu.resize(I.getHeight(),I.getWidth(), 0.0);
137  Iv.resize(I.getHeight(),I.getWidth(), 0.0);
138 
139  if (convolve) {
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++) {
142  double conv_u = 0;
143  double conv_v = 0;
144 
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]; //Convolution
148  conv_u += M[a][b] * val;
149  conv_v += M[b][a] * val;
150  }
151  }
152  Iu[v][u] = conv_u;
153  Iv[v][u] = conv_v;
154  }
155  }
156  } else {
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++) {
159  double conv_u = 0;
160  double conv_v = 0;
161 
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]; //Correlation
165  conv_u += M[a][b] * val;
166  conv_v += M[b][a] * val;
167  }
168  }
169  Iu[v][u] = conv_u;
170  Iv[v][u] = conv_v;
171  }
172  }
173  }
174 }
175 
226 void
228  vpImage<double>& If,
229  const vpColVector& kernelH,
230  const vpColVector &kernelV) {
231  unsigned int size = kernelH.size();
232  unsigned int half_size = size/2;
233 
234  If.resize(I.getHeight(),I.getWidth(), 0.0);
235  vpImage<double> I_filter(I.getHeight(),I.getWidth(), 0.0);
236 
237  for (unsigned int i = 0; i < I.getHeight(); i++) {
238  for (unsigned int j = half_size; j < I.getWidth()-half_size; j++) {
239  double conv = 0.0;
240  for (unsigned int a = 0; a < kernelH.size(); a++) {
241  conv += kernelH[a] * I[i][j+half_size-a];
242  }
243 
244  I_filter[i][j] = conv;
245  }
246  }
247 
248  for (unsigned int i = half_size; i < I.getHeight()-half_size; i++) {
249  for (unsigned int j = 0; j < I.getWidth(); j++) {
250  double conv = 0.0;
251  for (unsigned int a = 0; a < kernelV.size(); a++) {
252  conv += kernelV[a] * I_filter[i+half_size-a][j];
253  }
254 
255  If[i][j] = conv;
256  }
257  }
258 }
259 
260 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
261 
301 void
304  const unsigned int gaussianFilterSize,
305  const double thresholdCanny,
306  const unsigned int apertureSobel)
307 {
308 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
309  IplImage* img_ipl = NULL;
310  vpImageConvert::convert(Isrc, img_ipl);
311  IplImage* edges_ipl;
312  edges_ipl = cvCreateImage(cvSize(img_ipl->width, img_ipl->height), img_ipl->depth, img_ipl->nChannels);
313 
314  cvSmooth(img_ipl, img_ipl, CV_GAUSSIAN, (int)gaussianFilterSize, (int)gaussianFilterSize, 0, 0);
315  cvCanny(img_ipl, edges_ipl, thresholdCanny, thresholdCanny, (int)apertureSobel);
316 
317  vpImageConvert::convert(edges_ipl, Ires);
318  cvReleaseImage(&img_ipl);
319  cvReleaseImage(&edges_ipl);
320 #else
321  cv::Mat img_cvmat, edges_cvmat;
322  vpImageConvert::convert(Isrc, img_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);
325  vpImageConvert::convert(edges_cvmat, Ires);
326 #endif
327 }
328 #endif
329 
333 void vpImageFilter::filter(const vpImage<unsigned char> &I, vpImage<double>& GI, const double *filter,unsigned int size)
334 {
335  vpImage<double> GIx ;
336  filterX(I, GIx,filter,size);
337  filterY(GIx, GI,filter,size);
338  GIx.destroy();
339 }
340 
344 void vpImageFilter::filter(const vpImage<double> &I, vpImage<double>& GI, const double *filter,unsigned int size)
345 {
346  vpImage<double> GIx ;
347  filterX(I, GIx,filter,size);
348  filterY(GIx, GI,filter,size);
349  GIx.destroy();
350 }
351 
352 void vpImageFilter::filterX(const vpImage<unsigned char> &I, vpImage<double>& dIx, const double *filter,unsigned int size)
353 {
354  dIx.resize(I.getHeight(),I.getWidth()) ;
355  for (unsigned int i=0 ; i < I.getHeight() ; i++)
356  {
357  for (unsigned int j=0 ; j < (size-1)/2 ; j++)
358  {
359  dIx[i][j]=vpImageFilter::filterXLeftBorder(I,i,j,filter,size);
360  //dIx[i][j]=0;
361  }
362  for (unsigned int j=(size-1)/2 ; j < I.getWidth()-(size-1)/2 ; j++)
363  {
364  dIx[i][j]=vpImageFilter::filterX(I,i,j,filter,size);
365  }
366  for (unsigned int j=I.getWidth()-(size-1)/2 ; j < I.getWidth() ; j++)
367  {
368  dIx[i][j]=vpImageFilter::filterXRightBorder(I,i,j,filter,size);
369  //dIx[i][j]=0;
370  }
371  }
372 }
373 void vpImageFilter::filterX(const vpImage<double> &I, vpImage<double>& dIx, const double *filter,unsigned int size)
374 {
375  dIx.resize(I.getHeight(),I.getWidth()) ;
376  for (unsigned int i=0 ; i < I.getHeight() ; i++)
377  {
378  for (unsigned int j=0 ; j < (size-1)/2 ; j++)
379  {
380  dIx[i][j]=vpImageFilter::filterXLeftBorder(I,i,j,filter,size);
381  //dIx[i][j]=0;
382  }
383  for (unsigned int j=(size-1)/2 ; j < I.getWidth()-(size-1)/2 ; j++)
384  {
385  dIx[i][j]=vpImageFilter::filterX(I,i,j,filter,size);
386  }
387  for (unsigned int j=I.getWidth()-(size-1)/2 ; j < I.getWidth() ; j++)
388  {
389  dIx[i][j]=vpImageFilter::filterXRightBorder(I,i,j,filter,size);
390  //dIx[i][j]=0;
391  }
392  }
393 }
394 void vpImageFilter::filterY(const vpImage<unsigned char> &I, vpImage<double>& dIy, const double *filter,unsigned int size)
395 {
396  dIy.resize(I.getHeight(),I.getWidth()) ;
397  for (unsigned int i=0 ; i < (size-1)/2 ; i++)
398  {
399  for (unsigned int j=0 ; j < I.getWidth() ; j++)
400  {
401  dIy[i][j]=vpImageFilter::filterYTopBorder(I,i,j,filter,size);
402  }
403  }
404  for (unsigned int i=(size-1)/2 ; i < I.getHeight()-(size-1)/2 ; i++)
405  {
406  for (unsigned int j=0 ; j < I.getWidth() ; j++)
407  {
408  dIy[i][j]=vpImageFilter::filterY(I,i,j,filter,size);
409  }
410  }
411  for (unsigned int i=I.getHeight()-(size-1)/2 ; i < I.getHeight() ; i++)
412  {
413  for (unsigned int j=0 ; j < I.getWidth() ; j++)
414  {
415  dIy[i][j]=vpImageFilter::filterYBottomBorder(I,i,j,filter,size);
416  }
417  }
418 }
419 void vpImageFilter::filterY(const vpImage<double> &I, vpImage<double>& dIy, const double *filter,unsigned int size)
420 {
421  dIy.resize(I.getHeight(),I.getWidth()) ;
422  for (unsigned int i=0 ; i < (size-1)/2 ; i++)
423  {
424  for (unsigned int j=0 ; j < I.getWidth() ; j++)
425  {
426  dIy[i][j]=vpImageFilter::filterYTopBorder(I,i,j,filter,size);
427  }
428  }
429  for (unsigned int i=(size-1)/2 ; i < I.getHeight()-(size-1)/2 ; i++)
430  {
431  for (unsigned int j=0 ; j < I.getWidth() ; j++)
432  {
433  dIy[i][j]=vpImageFilter::filterY(I,i,j,filter,size);
434  }
435  }
436  for (unsigned int i=I.getHeight()-(size-1)/2 ; i < I.getHeight() ; i++)
437  {
438  for (unsigned int j=0 ; j < I.getWidth() ; j++)
439  {
440  dIy[i][j]=vpImageFilter::filterYBottomBorder(I,i,j,filter,size);
441  }
442  }
443 }
444 
454 void vpImageFilter::gaussianBlur(const vpImage<unsigned char> &I, vpImage<double>& GI, unsigned int size, double sigma, bool normalize)
455 {
456  double *fg=new double[(size+1)/2] ;
457  vpImageFilter::getGaussianKernel(fg, size, sigma, normalize) ;
458  vpImage<double> GIx ;
459  vpImageFilter::filterX(I, GIx,fg,size);
460  vpImageFilter::filterY(GIx, GI,fg,size);
461  GIx.destroy();
462  delete[] fg;
463 }
464 
474 void vpImageFilter::gaussianBlur(const vpImage<double> &I, vpImage<double>& GI, unsigned int size, double sigma, bool normalize)
475 {
476  double *fg=new double[(size+1)/2] ;
477  vpImageFilter::getGaussianKernel(fg, size, sigma, normalize) ;
478  vpImage<double> GIx ;
479  vpImageFilter::filterX(I, GIx,fg,size);
480  vpImageFilter::filterY(GIx, GI,fg,size);
481  GIx.destroy();
482  delete[] fg;
483 }
484 
494 void vpImageFilter::getGaussianKernel(double *filter, unsigned int size, double sigma, bool normalize)
495 {
496  if (size%2 != 1)
498  "Bad Gaussian filter size"));
499 
500  if (sigma<= 0)
501  sigma = (size-1)/6.0;
502 
503  int middle = (int)(size-1)/2;
504  double sigma2 = vpMath::sqr(sigma);
505  for( int i=0; i<= middle; i++)
506  {
507  filter[i] = (1./(sigma*sqrt(2.*M_PI)))*exp(-(i*i)/(2.*sigma2));
508  }
509  if (normalize) {
510  //renormalization
511  double sum=0;
512  for(int i=1; i<=middle; i++)
513  {
514  sum += 2*filter[i] ;
515  }
516  sum += filter[0];
517 
518  for(int i=0; i<=middle; i++)
519  {
520  filter[i] = filter[i]/sum;
521  }
522  }
523 }
524 
534 void vpImageFilter::getGaussianDerivativeKernel(double *filter, unsigned int size, double sigma, bool normalize)
535 {
536  if (size%2 != 1)
538  "Bad Gaussian filter size"));
539 
540  if (sigma<= 0)
541  sigma = (size-1)/6.0;
542 
543  int middle = (int)(size-1)/2;
544  double sigma2 = vpMath::sqr(sigma);
545  filter[0] = 0.;
546  for(int i=1; i<= middle; i++)
547  {
548  filter[i] = -(1./(sigma*sqrt(2.*M_PI)))*(exp(-((i+1)*(i+1))/(2.*sigma2))-exp(-((i-1)*(i-1))/(2.*sigma2)))/2.;
549  }
550 
551  if (normalize) {
552  double sum=0;
553  for(int i=1; i<=middle; i++)
554  {
555  sum += 2.*(1./(sigma*sqrt(2.*M_PI)))*exp(-(i*i)/(2.*sigma2));
556  }
557  sum += (1./(sigma*sqrt(2.*M_PI))) ;
558 
559  for(int i=1; i<=middle; i++)
560  {
561  filter[i] = filter[i]/sum;
562  }
563  }
564 }
565 
566 
568 {
569  dIx.resize(I.getHeight(),I.getWidth()) ;
570  //dIx=0;
571  for (unsigned int i=0 ; i < I.getHeight() ; i++)
572  {
573  for (unsigned int j=0 ; j < 3 ; j++)
574  {
575  dIx[i][j]=0;
576  }
577  for (unsigned int j=3 ; j < I.getWidth()-3 ; j++)
578  {
579  dIx[i][j]=vpImageFilter::derivativeFilterX(I,i,j);
580  }
581  for (unsigned int j=I.getWidth()-3 ; j < I.getWidth() ; j++)
582  {
583  dIx[i][j]=0;
584  }
585  }
586 }
587 
589 {
590  dIy.resize(I.getHeight(),I.getWidth()) ;
591  //dIy=0;
592  for (unsigned int i=0 ; i < 3 ; i++)
593  {
594  for (unsigned int j=0 ; j < I.getWidth() ; j++)
595  {
596  dIy[i][j]=0;
597  }
598  }
599  for (unsigned int i=3 ; i < I.getHeight()-3 ; i++)
600  {
601  for (unsigned int j=0 ; j < I.getWidth() ; j++)
602  {
603  dIy[i][j]=vpImageFilter::derivativeFilterY(I,i,j);
604  }
605  }
606  for (unsigned int i=I.getHeight()-3 ; i < I.getHeight() ; i++)
607  {
608  for (unsigned int j=0 ; j < I.getWidth() ; j++)
609  {
610  dIy[i][j]=0;
611  }
612  }
613 }
614 
615 void vpImageFilter::getGradX(const vpImage<unsigned char> &I, vpImage<double>& dIx, const double *filter,unsigned int size)
616 {
617  dIx.resize(I.getHeight(),I.getWidth()) ;
618  //#pragma omp parallel for
619  for (unsigned int i=0 ; i < I.getHeight() ; i++)
620  {
621  for (unsigned int j=0 ; j < (size-1)/2 ; j++)
622  {
623  dIx[i][j]=0;
624  }
625  for (unsigned int j=(size-1)/2 ; j < I.getWidth()-(size-1)/2 ; j++)
626  {
627  dIx[i][j]=vpImageFilter::derivativeFilterX(I,i,j,filter,size);
628  }
629  for (unsigned int j=I.getWidth()-(size-1)/2 ; j < I.getWidth() ; j++)
630  {
631  dIx[i][j]=0;
632  }
633  }
634 }
635 void vpImageFilter::getGradX(const vpImage<double> &I, vpImage<double>& dIx, const double *filter,unsigned int size)
636 {
637  dIx.resize(I.getHeight(),I.getWidth()) ;
638  //dIx=0;
639  for (unsigned int i=0 ; i < I.getHeight() ; i++)
640  {
641  for (unsigned int j=0 ; j < (size-1)/2 ; j++)
642  {
643  dIx[i][j]=0;
644  }
645  for (unsigned int j=(size-1)/2 ; j < I.getWidth()-(size-1)/2 ; j++)
646  {
647  dIx[i][j]=vpImageFilter::derivativeFilterX(I,i,j,filter,size);
648  }
649  for (unsigned int j=I.getWidth()-(size-1)/2 ; j < I.getWidth() ; j++)
650  {
651  dIx[i][j]=0;
652  }
653  }
654 }
655 
656 void vpImageFilter::getGradY(const vpImage<unsigned char> &I, vpImage<double>& dIy, const double *filter,unsigned int size)
657 {
658  dIy.resize(I.getHeight(),I.getWidth()) ;
659  //#pragma omp parallel for
660  for (unsigned int i=0 ; i < (size-1)/2 ; i++)
661  {
662  for (unsigned int j=0 ; j < I.getWidth() ; j++)
663  {
664  dIy[i][j]=0;
665  }
666  }
667  //#pragma omp parallel for
668  for (unsigned int i=(size-1)/2 ; i < I.getHeight()-(size-1)/2 ; i++)
669  {
670  for (unsigned int j=0 ; j < I.getWidth() ; j++)
671  {
672  dIy[i][j]=vpImageFilter::derivativeFilterY(I,i,j,filter,size);
673  }
674  }
675  //#pragma omp parallel for
676  for (unsigned int i=I.getHeight()-(size-1)/2 ; i < I.getHeight() ; i++)
677  {
678  for (unsigned int j=0 ; j < I.getWidth() ; j++)
679  {
680  dIy[i][j]=0;
681  }
682  }
683 }
684 
685 void vpImageFilter::getGradY(const vpImage<double> &I, vpImage<double>& dIy, const double *filter,unsigned int size)
686 {
687  dIy.resize(I.getHeight(),I.getWidth()) ;
688  //dIy=0;
689  for (unsigned int i=0 ; i < (size-1)/2 ; i++)
690  {
691  for (unsigned int j=0 ; j < I.getWidth() ; j++)
692  {
693  dIy[i][j]=0;
694  }
695  }
696  for (unsigned int i=(size-1)/2 ; i < I.getHeight()-(size-1)/2 ; i++)
697  {
698  for (unsigned int j=0 ; j < I.getWidth() ; j++)
699  {
700  dIy[i][j]=vpImageFilter::derivativeFilterY(I,i,j,filter,size);
701  }
702  }
703  for (unsigned int i=I.getHeight()-(size-1)/2 ; i < I.getHeight() ; i++)
704  {
705  for (unsigned int j=0 ; j < I.getWidth() ; j++)
706  {
707  dIy[i][j]=0;
708  }
709  }
710 }
711 
720 void vpImageFilter::getGradXGauss2D(const vpImage<unsigned char> &I, vpImage<double>& dIx, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
721 {
722  vpImage<double> GIy;
723  vpImageFilter::filterY(I, GIy, gaussianKernel, size);
724  vpImageFilter::getGradX(GIy, dIx, gaussianDerivativeKernel, size);
725 }
726 
735 void vpImageFilter::getGradYGauss2D(const vpImage<unsigned char> &I, vpImage<double>& dIy, const double *gaussianKernel, const double *gaussianDerivativeKernel,unsigned int size)
736 {
737  vpImage<double> GIx;
738  vpImageFilter::filterX(I, GIx, gaussianKernel, size);
739  vpImageFilter::getGradY(GIx, dIy, gaussianDerivativeKernel, size);
740 }
741 
742 //operation pour pyramide gaussienne
744 {
746 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
747  cv::Mat imgsrc, imgdest;
748  vpImageConvert::convert(I, imgsrc);
749  cv::pyrDown( imgsrc, imgdest, cv::Size((int)I.getWidth()/2,(int)I.getHeight()/2));
750  vpImageConvert::convert(imgdest, GI);
751 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020408)
752  cv::Mat imgsrc, imgdest;
753  vpImageConvert::convert(I, imgsrc);
754  cv::pyrDown( imgsrc, imgdest, cvSize((int)I.getWidth()/2,(int)I.getHeight()/2));
755  vpImageConvert::convert(imgdest, GI);
756 #elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
757  IplImage* imgsrc = NULL;//cvCreateImage(cvGetSize(imgign), IPL_DEPTH_8U, 1);
758  IplImage* imgdest = NULL;//cvCreateImage(cvGetSize(imgign), IPL_DEPTH_8U, 1);
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);
761  vpImageConvert::convert(I,imgsrc);
762  cvPyrDown( imgsrc, imgdest);
763  vpImageConvert::convert(imgdest,GI);
764 
765  cvReleaseImage(&imgsrc);
766  cvReleaseImage(&imgdest);
767  //vpImage<unsigned char> sGI;sGI=GI;
768 
769 #else
772 #endif
773 }
774 
776 {
777 #if 0
778  GI.resize(I.getHeight(),(int)((I.getWidth()+1.)/2.)) ;
779  for (unsigned int i=0 ; i < I.getHeight() ; i++)
780  {
781  GI[i][0]=I[i][0];
782  for (unsigned int j=1 ; j < ((I.getWidth()+1.)/2.)-1 ; j++)
783  {
784  GI[i][j]=vpImageFilter::filterGaussXPyramidal(I,i,2*j);
785  }
786  GI[i][(int)((I.getWidth()+1.)/2.)-1]=I[i][2*((int)((I.getWidth()+1.)/2.)-1)];
787  }
788 #else
789  unsigned int w = I.getWidth()/2;
790 
791  GI.resize(I.getHeight(), w) ;
792  for (unsigned int i=0 ; i < I.getHeight() ; i++)
793  {
794  GI[i][0]=I[i][0];
795  for (unsigned int j=1 ; j < w-1 ; j++)
796  {
797  GI[i][j]=vpImageFilter::filterGaussXPyramidal(I,i,2*j);
798  }
799  GI[i][w-1]=I[i][2*w-1];
800  }
801 
802 #endif
803 }
805 {
806 
807 #ifdef ORIG
808  GI.resize((int)((I.getHeight()+1.)/2.),I.getWidth()) ;
809  for (unsigned int j=0 ; j < I.getWidth() ; j++)
810  {
811  GI[0][j]=I[0][j];
812  for (unsigned int i=1 ; i < ((I.getHeight()+1.)/2.)-1 ; i++)
813  {
814  GI[i][j]=vpImageFilter::filterGaussYPyramidal(I,2*i,j);
815  }
816  GI[(int)((I.getHeight()+1.)/2.)-1][j]=I[2*((int)((I.getHeight()+1.)/2.)-1)][j];
817  }
818 
819 #else
820  unsigned int h = I.getHeight()/2;
821 
822  GI.resize(h, I.getWidth()) ;
823  for (unsigned int j=0 ; j < I.getWidth() ; j++)
824  {
825  GI[0][j]=I[0][j];
826  for (unsigned int i=1 ; i < h-1 ; i++)
827  {
828  GI[i][j]=vpImageFilter::filterGaussYPyramidal(I,2*i,j);
829  }
830  GI[h-1][j]=I[2*h-1][j];
831  }
832 #endif
833 }
834 
835 
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
static double filterXLeftBorder(const vpImage< unsigned char > &I, unsigned int r, unsigned int c, const double *filter, unsigned int size)
unsigned int getWidth() const
Definition: vpImage.h:226
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.
Definition: vpArray2D.h:156
unsigned int getCols() const
Return the number of columns of the 2D array.
Definition: vpArray2D.h:154
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)
Definition: vpMath.h:110
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
Definition: vpImage.h:903
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
void destroy()
Destructor : Memory de-allocation.
Definition: vpImage.h:959
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.
Definition: vpColVector.h:72
static unsigned char filterGaussXPyramidal(const vpImage< unsigned char > &I, unsigned int i, unsigned int j)
unsigned int getHeight() const
Definition: vpImage.h:175
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)
Definition: vpImageFilter.h:86