ViSP  2.9.0
vpImageMorphology.h
1 /****************************************************************************
2  *
3  * $Id: vpImageMorphology.h 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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  * Morphology tools.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 
43 #ifndef vpImageMorphology_H
44 #define vpImageMorphology_H
45 
51 #include <visp/vpImage.h>
52 #include <visp/vpImageException.h>
53 #include <visp/vpMatrix.h>
54 
55 #include <fstream>
56 #include <iostream>
57 #include <math.h>
58 #include <string.h>
59 
72 {
73 public:
77  typedef enum {
83 
84 public:
85  template<class Type>
86  static void erosion(vpImage<Type> &I, Type value, Type value_out,
87  vpConnexityType connexity = CONNEXITY_4);
88 
89  template<class Type>
90  static void dilatation(vpImage<Type> &I, Type value, Type value_out,
91  vpConnexityType connexity = CONNEXITY_4);
92 
93 } ;
94 
112 template<class Type>
114  Type value,
115  Type value_out,
116  vpConnexityType connexity)
117 {
118  vpImage<Type> J(I.getHeight(), I.getWidth()) ;
119  J = I;
120 
121  if (connexity == CONNEXITY_4) {
122  for (unsigned int i=1 ; i < I.getHeight()-1 ; i++)
123  for (unsigned int j=1 ; j < I.getWidth()-1 ; j++)
124  {
125  if (I[i][j] == value)
126  {
127  // Consider 4 neighbors
128  if ((I[i-1][j] == value_out) ||
129  (I[i+1][j] == value_out) ||
130  (I[i][j-1] == value_out) ||
131  (I[i][j+1] == value_out))
132  J[i][j] = value_out;
133  }
134  }
135  }
136  else {
137  for (unsigned int i=1 ; i < I.getHeight()-1 ; i++)
138  for (unsigned int j=1 ; j < I.getWidth()-1 ; j++)
139  {
140  if (I[i][j] == value)
141  {
142  // Consider 8 neighbors
143  if ((I[i-1][j-1] == value_out) ||
144  (I[i-1][j] == value_out) ||
145  (I[i-1][j+1] == value_out) ||
146  (I[i][j-1] == value_out) ||
147  (I[i][j+1] == value_out) ||
148  (I[i+1][j+1] == value_out) ||
149  (I[i+1][j+1] == value_out) ||
150  (I[i+1][j+1] == value_out) )
151  J[i][j] = value_out ;
152  }
153  }
154 
155 
156  }
157  I = J ;
158 }
159 
177 template<class Type>
179  Type value,
180  Type value_out,
181  vpConnexityType connexity)
182 {
183  vpImage<Type> J(I.getHeight(), I.getWidth()) ;
184  J = I;
185  if (connexity == CONNEXITY_4) {
186  for (unsigned int i=1 ; i < I.getHeight()-1 ; i++)
187  for (unsigned int j=1 ; j < I.getWidth()-1 ; j++)
188  {
189  if (I[i][j] == value_out)
190  {
191  // Consider 4 neighbors
192  if ((I[i-1][j] == value) ||
193  (I[i+1][j] == value) ||
194  (I[i][j-1] == value) ||
195  (I[i][j+1] == value))
196  J[i][j] = value ;
197  }
198  }
199  }
200  else {
201  for (unsigned int i=1 ; i < I.getHeight()-1 ; i++)
202  for (unsigned int j=1 ; j < I.getWidth()-1 ; j++)
203  {
204  if (I[i][j] == value_out)
205  {
206  // Consider 8 neighbors
207  if ((I[i-1][j-1] == value) ||
208  (I[i-1][j] == value) ||
209  (I[i-1][j+1] == value) ||
210  (I[i][j-1] == value) ||
211  (I[i][j+1] == value) ||
212  (I[i+1][j+1] == value) ||
213  (I[i+1][j+1] == value) ||
214  (I[i+1][j+1] == value) )
215  J[i][j] = value ;
216  }
217  }
218  }
219 
220  I = J ;
221 }
222 #endif
223 
224 
225 /*
226  * Local variables:
227  * c-basic-offset: 2
228  * End:
229  */
Various mathematical morphology tools, erosion, dilatation...
static void dilatation(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
unsigned int getWidth() const
Definition: vpImage.h:159
static void erosion(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
unsigned int getHeight() const
Definition: vpImage.h:150
Definition of the vpImage class member functions.
Definition: vpImage.h:115