34 #include <visp3/core/vpConfig.h>
35 #include <visp3/core/vpImageFilter.h>
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 double vpImageFilter::filterXR(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
42 const unsigned int stop = (size - 1) / 2;
44 for (
unsigned int i = 1; i <= stop; ++i) {
45 result +=
filter[i] *
static_cast<double>(I[r][c + i].R + I[r][c - i].R);
47 return result + (
filter[0] *
static_cast<double>(I[r][c].R));
50 double vpImageFilter::filterXG(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
52 const unsigned int stop = (size - 1) / 2;
55 for (
unsigned int i = 1; i <= stop; ++i) {
56 result +=
filter[i] *
static_cast<double>(I[r][c + i].G + I[r][c - i].G);
58 return result + (
filter[0] *
static_cast<double>(I[r][c].G));
61 double vpImageFilter::filterXB(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
63 const unsigned int stop = (size - 1) / 2;
66 for (
unsigned int i = 1; i <= stop; ++i) {
67 result +=
filter[i] *
static_cast<double>(I[r][c + i].B + I[r][c - i].B);
69 return result + (
filter[0] *
static_cast<double>(I[r][c].B));
72 double vpImageFilter::filterXLeftBorderR(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
73 const double *filter,
unsigned int size)
75 const unsigned int stop = (size - 1) / 2;
78 for (
unsigned int i = 1; i <= stop; ++i) {
80 result +=
filter[i] *
static_cast<double>(I[r][c + i].R + I[r][c - i].R);
83 result +=
filter[i] *
static_cast<double>(I[r][c + i].R + I[r][i - c].R);
86 return result + (
filter[0] *
static_cast<double>(I[r][c].R));
89 double vpImageFilter::filterXLeftBorderG(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
90 const double *filter,
unsigned int size)
92 const unsigned int stop = (size - 1) / 2;
95 for (
unsigned int i = 1; i <= stop; ++i) {
97 result +=
filter[i] *
static_cast<double>(I[r][c + i].G + I[r][c - i].G);
100 result +=
filter[i] *
static_cast<double>(I[r][c + i].G + I[r][i - c].G);
103 return result + (
filter[0] *
static_cast<double>(I[r][c].G));
106 double vpImageFilter::filterXLeftBorderB(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
107 const double *filter,
unsigned int size)
109 const unsigned int stop = (size - 1) / 2;
112 for (
unsigned int i = 1; i <= stop; ++i) {
114 result +=
filter[i] *
static_cast<double>(I[r][c + i].B + I[r][c - i].B);
117 result +=
filter[i] *
static_cast<double>(I[r][c + i].B + I[r][i - c].B);
120 return result + (
filter[0] *
static_cast<double>(I[r][c].B));
123 double vpImageFilter::filterXRightBorderR(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
124 const double *filter,
unsigned int size)
126 const unsigned int stop = (size - 1) / 2;
127 const unsigned int width = I.
getWidth();
130 for (
unsigned int i = 1; i <= stop; ++i) {
131 if ((c + i) < width) {
132 result +=
filter[i] *
static_cast<double>(I[r][c + i].R + I[r][c - i].R);
135 result +=
filter[i] *
static_cast<double>(I[r][((2 * width) - c) - i - 1].R + I[r][c - i].R);
138 return result + (
filter[0] *
static_cast<double>(I[r][c].R));
141 double vpImageFilter::filterXRightBorderG(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
142 const double *filter,
unsigned int size)
144 const unsigned int stop = (size - 1) / 2;
145 const unsigned int width = I.
getWidth();
148 for (
unsigned int i = 1; i <= stop; ++i) {
149 if ((c + i) < width) {
150 result +=
filter[i] *
static_cast<double>(I[r][c + i].G + I[r][c - i].G);
153 result +=
filter[i] *
static_cast<double>(I[r][((2 * width) - c) - i - 1].G + I[r][c - i].G);
156 return result + (
filter[0] *
static_cast<double>(I[r][c].G));
159 double vpImageFilter::filterXRightBorderB(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
160 const double *filter,
unsigned int size)
162 const unsigned int stop = (size - 1) / 2;
163 const unsigned int width = I.
getWidth();
166 for (
unsigned int i = 1; i <= stop; ++i) {
167 if ((c + i) < width) {
168 result +=
filter[i] *
static_cast<double>(I[r][c + i].B + I[r][c - i].B);
171 result +=
filter[i] *
static_cast<double>(I[r][(2 * width) - c - i - 1].B + I[r][c - i].B);
174 return result + (
filter[0] *
static_cast<double>(I[r][c].B));
177 double vpImageFilter::filterYR(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
179 const unsigned int stop = (size - 1) / 2;
182 for (
unsigned int i = 1; i <= stop; ++i) {
183 result +=
filter[i] *
static_cast<double>(I[r + i][c].R + I[r - i][c].R);
185 return result + (
filter[0] *
static_cast<double>(I[r][c].R));
188 double vpImageFilter::filterYG(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
190 const unsigned int stop = (size - 1) / 2;
193 for (
unsigned int i = 1; i <= stop; ++i) {
194 result +=
filter[i] *
static_cast<double>(I[r + i][c].G + I[r - i][c].G);
196 return result + (
filter[0] *
static_cast<double>(I[r][c].G));
199 double vpImageFilter::filterYB(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
201 const unsigned int stop = (size - 1) / 2;
204 for (
unsigned int i = 1; i <= stop; ++i) {
205 result +=
filter[i] *
static_cast<double>(I[r + i][c].B + I[r - i][c].B);
207 return result + (
filter[0] *
static_cast<double>(I[r][c].B));
210 double vpImageFilter::filterYTopBorderR(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
212 const unsigned int stop = (size - 1) / 2;
215 for (
unsigned int i = 1; i <= stop; ++i) {
217 result +=
filter[i] *
static_cast<double>(I[r + i][c].R + I[r - i][c].R);
220 result +=
filter[i] *
static_cast<double>(I[r + i][c].R + I[i - r][c].R);
223 return result + (
filter[0] *
static_cast<double>(I[r][c].R));
226 double vpImageFilter::filterYTopBorderG(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
228 const unsigned int stop = (size - 1) / 2;
231 for (
unsigned int i = 1; i <= stop; ++i) {
233 result +=
filter[i] *
static_cast<double>(I[r + i][c].G + I[r - i][c].G);
236 result +=
filter[i] *
static_cast<double>(I[r + i][c].G + I[i - r][c].G);
239 return result + (
filter[0] *
static_cast<double>(I[r][c].G));
242 double vpImageFilter::filterYTopBorderB(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
const double *filter,
unsigned int size)
244 const unsigned int stop = (size - 1) / 2;
247 for (
unsigned int i = 1; i <= stop; ++i) {
249 result +=
filter[i] *
static_cast<double>(I[r + i][c].B + I[r - i][c].B);
252 result +=
filter[i] *
static_cast<double>(I[r + i][c].B + I[i - r][c].B);
255 return result + (
filter[0] *
static_cast<double>(I[r][c].B));
258 double vpImageFilter::filterYBottomBorderR(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
259 const double *filter,
unsigned int size)
261 const unsigned int height = I.
getHeight();
262 const unsigned int stop = (size - 1) / 2;
265 for (
unsigned int i = 1; i <= stop; ++i) {
266 if ((r + i) < height) {
267 result +=
filter[i] *
static_cast<double>(I[r + i][c].R + I[r - i][c].R);
270 result +=
filter[i] *
static_cast<double>(I[((2 * height) - r) - i - 1][c].R + I[r - i][c].R);
273 return result + (
filter[0] *
static_cast<double>(I[r][c].R));
276 double vpImageFilter::filterYBottomBorderG(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
277 const double *filter,
unsigned int size)
279 const unsigned int height = I.
getHeight();
280 const unsigned int stop = (size - 1) / 2;
283 for (
unsigned int i = 1; i <= stop; ++i) {
284 if ((r + i) < height) {
285 result +=
filter[i] *
static_cast<double>(I[r + i][c].G + I[r - i][c].G);
288 result +=
filter[i] *
static_cast<double>(I[((2 * height) - r) - i - 1][c].G + I[r - i][c].G);
291 return result + (
filter[0] *
static_cast<double>(I[r][c].G));
294 double vpImageFilter::filterYBottomBorderB(
const vpImage<vpRGBa> &I,
unsigned int r,
unsigned int c,
295 const double *filter,
unsigned int size)
297 const unsigned int height = I.
getHeight();
298 const unsigned int stop = (size - 1) / 2;
301 for (
unsigned int i = 1; i <= stop; ++i) {
302 if ((r + i) < height) {
303 result +=
filter[i] *
static_cast<double>(I[r + i][c].B + I[r - i][c].B);
306 result +=
filter[i] *
static_cast<double>(I[((2 * height) - r) - i - 1][c].B + I[r - i][c].B);
309 return result + (
filter[0] *
static_cast<double>(I[r][c].B));
static void filter(const vpImage< ImageType > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false, const vpImage< bool > *p_mask=nullptr)
unsigned int getWidth() const
unsigned int getHeight() const