Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpGaussianFilter.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 * Gaussian filter class
32 */
33
34#include <visp3/core/vpConfig.h>
35
36#if defined(VISP_HAVE_SIMDLIB)
37#include <Simd/SimdLib.h>
38#include <visp3/core/vpGaussianFilter.h>
39#include <visp3/core/vpImageConvert.h>
40
42#ifndef DOXYGEN_SHOULD_SKIP_THIS
43class vpGaussianFilter::Impl
44{
45public:
46 Impl(unsigned int width, unsigned int height, float sigma, bool deinterleave)
47 : m_funcPtrGray(nullptr), m_funcPtrRGBa(nullptr), m_deinterleave(deinterleave)
48 {
49 const float epsilon = 0.001f;
50
51 const size_t channels_1 = 1;
52 m_funcPtrGray = SimdGaussianBlurInit(width, height, channels_1, &sigma, &epsilon);
53
54 const size_t channels_4 = 4;
55 m_funcPtrRGBa = SimdGaussianBlurInit(width, height, channels_4, &sigma, &epsilon);
56
57 if (m_deinterleave) {
58 m_red.resize(height, width);
59 m_green.resize(height, width);
60 m_blue.resize(height, width);
61
62 m_redBlurred.resize(height, width);
63 m_greenBlurred.resize(height, width);
64 m_blueBlurred.resize(height, width);
65 }
66 }
67
68 ~Impl()
69 {
70 if (m_funcPtrGray) {
71 SimdRelease(m_funcPtrGray);
72 }
73
74 if (m_funcPtrRGBa) {
75 SimdRelease(m_funcPtrRGBa);
76 }
77 }
78
79 void apply(const vpImage<unsigned char> &I, vpImage<unsigned char> &I_blur)
80 {
81 I_blur.resize(I.getHeight(), I.getWidth());
82 SimdGaussianBlurRun(m_funcPtrGray, I.bitmap, I.getWidth(), I_blur.bitmap, I_blur.getWidth());
83 }
84
85 void apply(const vpImage<vpRGBa> &I, vpImage<vpRGBa> &I_blur)
86 {
87 I_blur.resize(I.getHeight(), I.getWidth());
88 if (!m_deinterleave) {
89 const unsigned int rgba_size = 4;
90 SimdGaussianBlurRun(m_funcPtrRGBa, reinterpret_cast<unsigned char *>(I.bitmap), I.getWidth() * rgba_size,
91 reinterpret_cast<unsigned char *>(I_blur.bitmap), I_blur.getWidth() * rgba_size);
92 }
93 else {
94 vpImageConvert::split(I, &m_red, &m_green, &m_blue);
95 SimdGaussianBlurRun(m_funcPtrGray, m_red.bitmap, m_red.getWidth(), m_redBlurred.bitmap, m_redBlurred.getWidth());
96 SimdGaussianBlurRun(m_funcPtrGray, m_green.bitmap, m_green.getWidth(), m_greenBlurred.bitmap,
97 m_greenBlurred.getWidth());
98 SimdGaussianBlurRun(m_funcPtrGray, m_blue.bitmap, m_blue.getWidth(), m_blueBlurred.bitmap,
99 m_blueBlurred.getWidth());
100
101 vpImageConvert::merge(&m_redBlurred, &m_greenBlurred, &m_blueBlurred, nullptr, I_blur);
102 }
103 }
104
105protected:
106 void *m_funcPtrGray;
107 void *m_funcPtrRGBa;
108 bool m_deinterleave;
109 vpImage<unsigned char> m_red;
110 vpImage<unsigned char> m_green;
111 vpImage<unsigned char> m_blue;
112 vpImage<unsigned char> m_redBlurred;
113 vpImage<unsigned char> m_greenBlurred;
114 vpImage<unsigned char> m_blueBlurred;
115};
116#endif // DOXYGEN_SHOULD_SKIP_THIS
117
128vpGaussianFilter::vpGaussianFilter(unsigned int width, unsigned int height, float sigma, bool deinterleave)
129 : m_impl(new Impl(width, height, sigma, deinterleave))
130{ }
131
133
141{
142 m_impl->apply(I, I_blur);
143}
144
151void vpGaussianFilter::apply(const vpImage<vpRGBa> &I, vpImage<vpRGBa> &I_blur) { m_impl->apply(I, I_blur); }
152END_VISP_NAMESPACE
153#elif !defined(VISP_BUILD_SHARED_LIBS)
154 // Work around to avoid warning: libvisp_core.a(vpGaussianFilter.cpp.o) has no symbols
155void dummy_vpGaussianFilter() { }
156
157#endif
vpGaussianFilter(unsigned int width, unsigned int height, float sigma, bool deinterleave=false)
void apply(const vpImage< unsigned char > &I, vpImage< unsigned char > &I_blur)
static void merge(const vpImage< unsigned char > *R, const vpImage< unsigned char > *G, const vpImage< unsigned char > *B, const vpImage< unsigned char > *a, vpImage< vpRGBa > &RGBa)
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=nullptr)
Definition of the vpImage class member functions.
Definition vpImage.h:131
unsigned int getWidth() const
Definition vpImage.h:242
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition vpImage.h:544
Type * bitmap
points toward the bitmap
Definition vpImage.h:135
unsigned int getHeight() const
Definition vpImage.h:181