ViSP  2.8.0
vpImageFilter.h
1 /****************************************************************************
2  *
3  * $Id: vpImageFilter.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Various image tools, convolution, ...
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
43 
44 #ifndef vpImageFilter_H
45 #define vpImageFilter_H
46 
53 #include <visp/vpImage.h>
54 #include <visp/vpImageException.h>
55 #include <visp/vpMatrix.h>
56 #include <visp/vpMath.h>
57 
58 #include <fstream>
59 #include <iostream>
60 #include <math.h>
61 #include <string.h>
62 
71 class VISP_EXPORT vpImageFilter
72 {
73 
74 public:
75  static void filter(const vpImage<double> &I,
76  vpImage<double>& Iu,
77  vpImage<double>& Iv,
78  const vpMatrix& M) ;
79 
80 
81  static void filter(const vpImage<unsigned char> &I,
82  vpImage<double>& If,
83  const vpMatrix& M) ;
84 
85 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
86  static void canny(const vpImage<unsigned char>& I,
88  const unsigned int gaussianFilterSize,
89  const double thresholdCanny,
90  const unsigned int apertureSobel);
91 #endif
92 
100  template<class T>
101  static double
103  const unsigned int r, const unsigned int c)
104  {
105  //filter Gaussien
106  return (
107  15.0 * fr[r][c]
108  + 12.0 * ( fr[r-1][c] + fr[r][c-1] + fr[r+1][c] + fr[r][c+1] )
109  + 9.0 * ( fr[r-1][c-1] + fr[r+1][c-1] + fr[r-1][c+1] + fr[r+1][c+1])
110  + 5.0 * ( fr[r-2][c] + fr[r][c-2] + fr[r+2][c] + fr[r][c+2] )
111  + 4.0 * ( fr[r-2][c+1] + fr[r-2][c-1] + fr[r-1][c-2] + fr[r+1][c-2] +
112  fr[r+2][c-1] + fr[r+2][c+1] + fr[r-1][c+2] + fr[r+1][c+2] )
113  + 2.0 * ( fr[r-2][c-2] + fr[r+2][c-2] + fr[r-2][c+2] + fr[r+2][c+2] )
114  )
115  /159.0;
116  }
117 
118 
119 
127  template<class T>
128  static double
130  const unsigned int r, const unsigned int c)
131  {
132  return (2047.0 *(fr[r][c+1] - fr[r][c-1])
133  +913.0 *(fr[r][c+2] - fr[r][c-2])
134  +112.0 *(fr[r][c+3] - fr[r][c-3]))/8418.0;
135  }
136 
144  template<class T>
145  static double
147  const unsigned int r, const unsigned int c)
148  {
149  return (2047.0 *(fr[r+1][c] - fr[r-1][c])
150  +913.0 *(fr[r+2][c] - fr[r-2][c])
151  +112.0 *(fr[r+3][c] - fr[r-3][c]))/8418.0;
152  }
153 
162  static void
163  coefficientGaussianDerivative(double *filter, const unsigned int t)
164  {
165  unsigned int i;
166  // double sigma;
167  if (filter == NULL)
168  filter = new double[t/2] ;
169 
170  double s2 = vpMath::sqr((t-1)/6.0);
171 
172  for(i=1; i<=(t-1)/2; i++)
173  {
174  filter[i] = (i/(s2*sqrt(2*M_PI)))*exp((i*i)/(-2*s2));
175 
176  }
177 
178  }
179 
180 
193  template<class T>
194  static double
196  const unsigned int r, const unsigned int c,
197  double *filter, const unsigned int size)
198  {
199  unsigned int i;
200  double result;
201 
202  result = 0;
203 
204  for(i=1; i<=(size-1)/2; i++)
205  {
206  result += filter[i]*(I[r][c+i] - I[r][c-i]) ;
207  }
208  return result;
209  }
210 
211 
212 
224  template<class T>
225  static double
227  const unsigned int r, const unsigned int c,
228  double *filter, const unsigned int size)
229  {
230  unsigned int i;
231  double result;
232 
233  result = 0;
234 
235  for(i=1; i<=(size-1)/2; i++)
236  {
237  result += filter[i]*(I[r+i][c] - I[r-i][c]) ;
238  }
239  return result;
240  }
241 } ;
242 
243 
244 #endif
245 
246 
247 /*
248  * Local variables:
249  * c-basic-offset: 2
250  * End:
251  */
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
static void coefficientGaussianDerivative(double *filter, const unsigned int t)
static double gaussianFilter(vpImage< T > &fr, const unsigned int r, const unsigned int c)
static double derivativeFilterY(vpImage< T > &I, const unsigned int r, const unsigned int c, double *filter, const unsigned int size)
static double derivativeFilterX(vpImage< T > &fr, const unsigned int r, const unsigned int c)
static double derivativeFilterX(vpImage< T > &I, const unsigned int r, const unsigned int c, double *filter, const unsigned int size)
static double derivativeFilterY(vpImage< T > &fr, const unsigned int r, const unsigned int c)
static double sqr(double x)
Definition: vpMath.h:106
Definition of the vpImage class member functions.
Definition: vpImage.h:115
Various image filter, convolution, etc...
Definition: vpImageFilter.h:71