ViSP  2.10.0
vpImageTools.cpp
1 /****************************************************************************
2  *
3  * $Id: vpImageTools.cpp 5236 2015-01-30 13:51:42Z 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  * Image tools.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 #include <visp/vpImageTools.h>
43 
44 
103  unsigned char A,
104  unsigned char A_star,
105  unsigned char B,
106  unsigned char B_star)
107 {
108  // Test if input values are valid
109  if (B <= A) {
110  vpERROR_TRACE("Bad gray levels") ;
112  "Bad gray levels")) ;
113  }
114  unsigned char v;
115 
116  double factor = (double)(B_star - A_star)/(double)(B - A);
117 
118  for (unsigned int i=0 ; i < I.getHeight(); i++)
119  for (unsigned int j=0 ; j < I.getWidth(); j++) {
120  v = I[i][j];
121 
122  if (v <= A)
123  I[i][j] = A_star;
124  else if (v >= B)
125  I[i][j] = B_star;
126  else
127  I[i][j] = (unsigned char)(A_star + factor*(v-A));
128  }
129 }
130 
144  const vpImage<unsigned char> &I2,
145  vpImage<unsigned char> &Idiff)
146 {
147  if ((I1.getHeight() != I2.getHeight()) || (I1.getWidth() != I2.getWidth()))
148  {
149  throw (vpException(vpException::dimensionError, "The two images have not the same size"));
150  }
151 
152  if ((I1.getHeight() != Idiff.getHeight()) || (I1.getWidth() != Idiff.getWidth()))
153  Idiff.resize(I1.getHeight(), I1.getWidth());
154 
155  unsigned int n = I1.getHeight() * I1.getWidth() ;
156  int diff ;
157  for (unsigned int b = 0; b < n ; b++)
158  {
159  diff = I1.bitmap[b] - I2.bitmap[b] + 128;
160  Idiff.bitmap[b] = (unsigned char)
161  (vpMath::maximum(vpMath::minimum(diff, 255), 0));
162  }
163 }
164 
176 void
178  const vpImage<unsigned char> &I2,
179  vpImage<unsigned char> &Idiff)
180 {
181  if ((I1.getHeight() != I2.getHeight()) || (I1.getWidth() != I2.getWidth()))
182  {
183  throw (vpException(vpException::dimensionError, "The two images do not have the same size"));
184  }
185 
186  if ((I1.getHeight() != Idiff.getHeight()) || (I1.getWidth() != Idiff.getWidth()))
187  Idiff.resize(I1.getHeight(), I1.getWidth());
188 
189  unsigned int n = I1.getHeight() * I1.getWidth() ;
190  int diff ;
191  for (unsigned int b = 0; b < n ; b++)
192  {
193  diff = I1.bitmap[b] - I2.bitmap[b];
194  Idiff.bitmap[b] = diff;
195  }
196 }
197 
198 /*
199  * Local variables:
200  * c-basic-offset: 2
201  * End:
202  */
static void imageDifferenceAbsolute(const vpImage< unsigned char > &I1, const vpImage< unsigned char > &I2, vpImage< unsigned char > &Idiff)
unsigned int getWidth() const
Definition: vpImage.h:161
#define vpERROR_TRACE
Definition: vpDebug.h:395
Type * bitmap
points toward the bitmap
Definition: vpImage.h:120
error that can be emited by ViSP classes.
Definition: vpException.h:76
Error that can be emited by the vpImage class and its derivates.
static void imageDifference(const vpImage< unsigned char > &I1, const vpImage< unsigned char > &I2, vpImage< unsigned char > &Idiff)
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
Definition: vpImage.h:536
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:148
unsigned int getHeight() const
Definition: vpImage.h:152
static void changeLUT(vpImage< unsigned char > &I, unsigned char A, unsigned char newA, unsigned char B, unsigned char newB)