Visual Servoing Platform  version 3.0.0
vpImageTools.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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  * Image tools.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 #include <visp3/core/vpImageTools.h>
39 
40 
99  unsigned char A,
100  unsigned char A_star,
101  unsigned char B,
102  unsigned char B_star)
103 {
104  // Test if input values are valid
105  if (B <= A) {
106  vpERROR_TRACE("Bad gray levels") ;
108  "Bad gray levels")) ;
109  }
110  unsigned char v;
111 
112  double factor = (double)(B_star - A_star)/(double)(B - A);
113 
114  for (unsigned int i=0 ; i < I.getHeight(); i++)
115  for (unsigned int j=0 ; j < I.getWidth(); j++) {
116  v = I[i][j];
117 
118  if (v <= A)
119  I[i][j] = A_star;
120  else if (v >= B)
121  I[i][j] = B_star;
122  else
123  I[i][j] = (unsigned char)(A_star + factor*(v-A));
124  }
125 }
126 
140  const vpImage<unsigned char> &I2,
141  vpImage<unsigned char> &Idiff)
142 {
143  if ((I1.getHeight() != I2.getHeight()) || (I1.getWidth() != I2.getWidth()))
144  {
145  throw (vpException(vpException::dimensionError, "The two images have not the same size"));
146  }
147 
148  if ((I1.getHeight() != Idiff.getHeight()) || (I1.getWidth() != Idiff.getWidth()))
149  Idiff.resize(I1.getHeight(), I1.getWidth());
150 
151  unsigned int n = I1.getHeight() * I1.getWidth() ;
152  int diff ;
153  for (unsigned int b = 0; b < n ; b++)
154  {
155  diff = I1.bitmap[b] - I2.bitmap[b] + 128;
156  Idiff.bitmap[b] = (unsigned char)
157  (vpMath::maximum(vpMath::minimum(diff, 255), 0));
158  }
159 }
160 
172 void
174  const vpImage<unsigned char> &I2,
175  vpImage<unsigned char> &Idiff)
176 {
177  if ((I1.getHeight() != I2.getHeight()) || (I1.getWidth() != I2.getWidth()))
178  {
179  throw (vpException(vpException::dimensionError, "The two images do not have the same size"));
180  }
181 
182  if ((I1.getHeight() != Idiff.getHeight()) || (I1.getWidth() != Idiff.getWidth()))
183  Idiff.resize(I1.getHeight(), I1.getWidth());
184 
185  unsigned int n = I1.getHeight() * I1.getWidth() ;
186  int diff ;
187  for (unsigned int b = 0; b < n ; b++)
188  {
189  diff = I1.bitmap[b] - I2.bitmap[b];
190  Idiff.bitmap[b] = diff;
191  }
192 }
193 
194 /*
195  * Local variables:
196  * c-basic-offset: 2
197  * End:
198  */
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
Type * bitmap
points toward the bitmap
Definition: vpImage.h:116
#define vpERROR_TRACE
Definition: vpDebug.h:391
error that can be emited by ViSP classes.
Definition: vpException.h:73
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:141
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
Definition: vpImage.h:616
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:152
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)