Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpImageFilter_xy.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
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 https://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 XY filtering.
32
*/
33
34
#include <visp3/core/vpConfig.h>
35
#include <visp3/core/vpImageFilter.h>
36
37
BEGIN_VISP_NAMESPACE
38
39
#ifndef DOXYGEN_SHOULD_SKIP_THIS
40
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
41
double
vpImageFilter::filterXR(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
42
{
43
const
unsigned
int
stop = (size - 1) / 2;
44
double
result = 0.;
45
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
46
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].R + I[
r
][c -
i
].R);
47
}
48
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].R));
49
}
50
51
double
vpImageFilter::filterXG(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
52
{
53
const
unsigned
int
stop = (size - 1) / 2;
54
double
result = 0.;
55
56
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
57
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].G + I[
r
][c -
i
].G);
58
}
59
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].G));
60
}
61
62
double
vpImageFilter::filterXB(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
63
{
64
const
unsigned
int
stop = (size - 1) / 2;
65
double
result = 0.;
66
67
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
68
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].B + I[
r
][c -
i
].B);
69
}
70
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].B));
71
}
72
73
double
vpImageFilter::filterXLeftBorderR(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
74
const
double
*filter,
unsigned
int
size)
75
{
76
const
unsigned
int
stop = (size - 1) / 2;
77
double
result = 0.;
78
79
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
80
if
(c > i) {
81
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].R + I[
r
][c -
i
].R);
82
}
83
else
{
84
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].R + I[
r
][
i
- c].R);
85
}
86
}
87
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].R));
88
}
89
90
double
vpImageFilter::filterXLeftBorderG(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
91
const
double
*filter,
unsigned
int
size)
92
{
93
const
unsigned
int
stop = (size - 1) / 2;
94
double
result = 0.;
95
96
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
97
if
(c > i) {
98
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].G + I[
r
][c -
i
].G);
99
}
100
else
{
101
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].G + I[
r
][
i
- c].G);
102
}
103
}
104
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].G));
105
}
106
107
double
vpImageFilter::filterXLeftBorderB(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
108
const
double
*filter,
unsigned
int
size)
109
{
110
const
unsigned
int
stop = (size - 1) / 2;
111
double
result = 0.;
112
113
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
114
if
(c > i) {
115
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].B + I[
r
][c -
i
].B);
116
}
117
else
{
118
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].B + I[
r
][
i
- c].B);
119
}
120
}
121
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].B));
122
}
123
124
double
vpImageFilter::filterXRightBorderR(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
125
const
double
*filter,
unsigned
int
size)
126
{
127
const
unsigned
int
val_2 = 2;
128
const
unsigned
int
stop = (size - 1) / 2;
129
const
unsigned
int
width
= I.
getWidth
();
130
double
result = 0.;
131
132
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
133
if
((c + i) < width) {
134
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].R + I[
r
][c -
i
].R);
135
}
136
else
{
137
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][((val_2 *
width
) - c) -
i
- 1].R + I[
r
][c -
i
].R);
138
}
139
}
140
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].R));
141
}
142
143
double
vpImageFilter::filterXRightBorderG(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
144
const
double
*filter,
unsigned
int
size)
145
{
146
const
unsigned
int
val_2 = 2;
147
const
unsigned
int
stop = (size - 1) / 2;
148
const
unsigned
int
width
= I.
getWidth
();
149
double
result = 0.;
150
151
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
152
if
((c + i) < width) {
153
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].G + I[
r
][c -
i
].G);
154
}
155
else
{
156
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][((val_2 *
width
) - c) -
i
- 1].G + I[
r
][c -
i
].G);
157
}
158
}
159
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].G));
160
}
161
162
double
vpImageFilter::filterXRightBorderB(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
163
const
double
*filter,
unsigned
int
size)
164
{
165
const
unsigned
int
val_2 = 2;
166
const
unsigned
int
stop = (size - 1) / 2;
167
const
unsigned
int
width
= I.
getWidth
();
168
double
result = 0.;
169
170
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
171
if
((c + i) < width) {
172
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][c +
i
].B + I[
r
][c -
i
].B);
173
}
174
else
{
175
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
][(val_2 *
width
) - c -
i
- 1].B + I[
r
][c -
i
].B);
176
}
177
}
178
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].B));
179
}
180
181
double
vpImageFilter::filterYR(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
182
{
183
const
unsigned
int
stop = (size - 1) / 2;
184
double
result = 0.;
185
186
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
187
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].R + I[
r
-
i
][c].R);
188
}
189
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].R));
190
}
191
192
double
vpImageFilter::filterYG(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
193
{
194
const
unsigned
int
stop = (size - 1) / 2;
195
double
result = 0.;
196
197
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
198
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].G + I[
r
-
i
][c].G);
199
}
200
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].G));
201
}
202
203
double
vpImageFilter::filterYB(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
204
{
205
const
unsigned
int
stop = (size - 1) / 2;
206
double
result = 0.;
207
208
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
209
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].B + I[
r
-
i
][c].B);
210
}
211
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].B));
212
}
213
214
double
vpImageFilter::filterYTopBorderR(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
215
{
216
const
unsigned
int
stop = (size - 1) / 2;
217
double
result = 0.;
218
219
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
220
if
(r > i) {
221
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].R + I[
r
-
i
][c].R);
222
}
223
else
{
224
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].R + I[
i
-
r
][c].R);
225
}
226
}
227
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].R));
228
}
229
230
double
vpImageFilter::filterYTopBorderG(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
231
{
232
const
unsigned
int
stop = (size - 1) / 2;
233
double
result = 0.;
234
235
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
236
if
(r > i) {
237
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].G + I[
r
-
i
][c].G);
238
}
239
else
{
240
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].G + I[
i
-
r
][c].G);
241
}
242
}
243
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].G));
244
}
245
246
double
vpImageFilter::filterYTopBorderB(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
const
double
*filter,
unsigned
int
size)
247
{
248
const
unsigned
int
stop = (size - 1) / 2;
249
double
result = 0.;
250
251
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
252
if
(r > i) {
253
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].B + I[
r
-
i
][c].B);
254
}
255
else
{
256
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].B + I[
i
-
r
][c].B);
257
}
258
}
259
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].B));
260
}
261
262
double
vpImageFilter::filterYBottomBorderR(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
263
const
double
*filter,
unsigned
int
size)
264
{
265
const
unsigned
int
val_2 = 2;
266
const
unsigned
int
height
= I.
getHeight
();
267
const
unsigned
int
stop = (size - 1) / 2;
268
double
result = 0.;
269
270
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
271
if
((r + i) < height) {
272
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].R + I[
r
-
i
][c].R);
273
}
274
else
{
275
result +=
filter
[
i
] *
static_cast<
double
>
(I[((val_2 *
height
) -
r
) -
i
- 1][c].R + I[
r
-
i
][c].R);
276
}
277
}
278
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].R));
279
}
280
281
double
vpImageFilter::filterYBottomBorderG(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
282
const
double
*filter,
unsigned
int
size)
283
{
284
const
unsigned
int
val_2 = 2;
285
const
unsigned
int
height
= I.
getHeight
();
286
const
unsigned
int
stop = (size - 1) / 2;
287
double
result = 0.;
288
289
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
290
if
((r + i) < height) {
291
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].G + I[
r
-
i
][c].G);
292
}
293
else
{
294
result +=
filter
[
i
] *
static_cast<
double
>
(I[((val_2 *
height
) -
r
) -
i
- 1][c].G + I[
r
-
i
][c].G);
295
}
296
}
297
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].G));
298
}
299
300
double
vpImageFilter::filterYBottomBorderB(
const
vpImage<vpRGBa>
&I,
unsigned
int
r,
unsigned
int
c,
301
const
double
*filter,
unsigned
int
size)
302
{
303
const
unsigned
int
val_2 = 2;
304
const
unsigned
int
height
= I.
getHeight
();
305
const
unsigned
int
stop = (size - 1) / 2;
306
double
result = 0.;
307
308
for
(
unsigned
int
i = 1;
i
<= stop; ++
i
) {
309
if
((r + i) < height) {
310
result +=
filter
[
i
] *
static_cast<
double
>
(I[
r
+
i
][c].B + I[
r
-
i
][c].B);
311
}
312
else
{
313
result +=
filter
[
i
] *
static_cast<
double
>
(I[((val_2 *
height
) -
r
) -
i
- 1][c].B + I[
r
-
i
][c].B);
314
}
315
}
316
return
result + (
filter
[0] *
static_cast<
double
>
(I[
r
][c].B));
317
}
318
319
#else
320
void
dummy_vpImageFilter_xy()
321
{
322
323
}
324
#endif
325
#endif
326
END_VISP_NAMESPACE
vpImageFilter::filter
static void filter(const vpImage< ImageType > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false, const vpImage< bool > *p_mask=nullptr)
Definition
vpImageFilter.h:715
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpImage::getWidth
unsigned int getWidth() const
Definition
vpImage.h:242
vpImage::getHeight
unsigned int getHeight() const
Definition
vpImage.h:181
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
yolo-centering-task-afma6.r
r
Definition
yolo-centering-task-afma6.py:220
yolo-centering-task-afma6.width
width
Definition
yolo-centering-task-afma6.py:329
yolo-centering-task-afma6.i
i
Definition
yolo-centering-task-afma6.py:329
yolo-centering-task-afma6.height
height
Definition
yolo-centering-task-afma6.py:329
modules
core
src
image
vpImageFilter_xy.cpp
Generated by
1.17.0