ViSP  2.8.0
vpImageFilter.cpp
1 /****************************************************************************
2  *
3  * $Id: vpImageFilter.cpp 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 #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) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
47 #include <cv.h>
48 #endif
49 
58 void
60  vpImage<double>& If,
61  const vpMatrix& M)
62 {
63 
64  unsigned int size = M.getRows() ;
65  unsigned int half_size = size/2 ;
66 
67  If.resize(I.getHeight(),I.getWidth()) ;
68 
69  If = 0 ;
70 
71  for (unsigned int i=half_size ; i < I.getHeight()-half_size ; i++)
72  {
73  for (unsigned int j=half_size ; j < I.getWidth()-half_size ; j++)
74  {
75  double conv_x = 0 ;
76 
77  for(unsigned int a = 0 ; a < size ; a++ )
78  for(unsigned int b = 0 ; b < size ; b++ )
79  {
80  double val = I[i-half_size+a][j-half_size+b] ;
81  conv_x += M[a][b] * val ;
82  }
83  If[i][j] = conv_x ;
84  }
85  }
86 
87 }
88 
98 void
100  vpImage<double>& Iu,
101  vpImage<double>& Iv,
102  const vpMatrix& M)
103 {
104 
105  unsigned int size = M.getRows() ;
106  unsigned int half_size = size/2 ;
107 
108  Iu.resize(I.getHeight(),I.getWidth()) ;
109  Iv.resize(I.getHeight(),I.getWidth()) ;
110 
111  Iu = 0 ;
112  Iv = 0 ;
113  for (unsigned int v=half_size ; v < I.getHeight()-half_size ; v++)
114  {
115  for (unsigned int u=half_size ; u < I.getWidth()-half_size ; u++)
116  {
117  double conv_u = 0 ;
118  double conv_v = 0 ;
119 
120  for(unsigned int a = 0 ; a < size ; a++ )
121  for(unsigned int b = 0 ; b < size ; b++ )
122  {
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 ;
126  }
127  Iu[v][u] = conv_u ;
128  Iv[v][u] = conv_v ;
129  }
130  }
131 
132 }
133 
134 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
135 
175 void
178  const unsigned int gaussianFilterSize,
179  const double thresholdCanny,
180  const unsigned int apertureSobel)
181 {
182  IplImage* img_ipl = NULL;
183  vpImageConvert::convert(Isrc, img_ipl);
184  IplImage* edges_ipl;
185  edges_ipl = cvCreateImage(cvSize(img_ipl->width, img_ipl->height), img_ipl->depth, img_ipl->nChannels);
186 
187  cvSmooth(img_ipl, img_ipl, CV_GAUSSIAN, (int)gaussianFilterSize, (int)gaussianFilterSize, 0, 0);
188  cvCanny(img_ipl, edges_ipl, thresholdCanny, thresholdCanny, (int)apertureSobel);
189 
190  vpImageConvert::convert(edges_ipl, Ires);
191  cvReleaseImage(&img_ipl);
192  cvReleaseImage(&edges_ipl);
193 }
194 #endif
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
unsigned int getWidth() const
Definition: vpImage.h:159
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:535
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M)
unsigned int getHeight() const
Definition: vpImage.h:150
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.
Definition: vpMatrix.h:157