ViSP
Main Page
Related Pages
Modules
Classes
Examples
All
Classes
Functions
Variables
Enumerations
Enumerator
Friends
Groups
Pages
vpImageTools.cpp
1
/****************************************************************************
2
*
3
* $Id: vpImageTools.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
* Image tools.
36
*
37
* Authors:
38
* Fabien Spindler
39
*
40
*****************************************************************************/
41
42
#include <visp/vpImageTools.h>
43
44
102
void
vpImageTools::changeLUT
(
vpImage<unsigned char>
& I,
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"
) ;
111
throw
(
vpImageException
(
vpImageException::incorrectInitializationError
,
112
"Bad gray levels"
)) ;
113
}
114
unsigned
char
v;
115
116
double
factor = (B_star - A_star)/(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
143
void
vpImageTools::imageDifference
(
const
vpImage<unsigned char>
&I1,
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
177
vpImageTools::imageDifferenceAbsolute
(
const
vpImage<unsigned char>
&I1,
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
*/
src
image
vpImageTools.cpp
Generated on Tue Sep 17 2013 00:21:36 for ViSP by
1.8.4