Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpGaussianFilter.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Gaussian filter class
33  *
34  *****************************************************************************/
35 
36 #include <visp3/core/vpGaussianFilter.h>
37 #include <visp3/core/vpImageConvert.h>
38 #include <Simd/SimdLib.h>
39 
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 class vpGaussianFilter::Impl
42 {
43 public:
44  Impl(unsigned int width, unsigned int height, float sigma, bool deinterleave)
45  : m_funcPtrGray(NULL), m_funcPtrRGBa(NULL), m_deinterleave(deinterleave)
46  {
47  const float epsilon = 0.001f;
48  {
49  const size_t channels = 1;
50  m_funcPtrGray = SimdGaussianBlurInit(width, height, channels, &sigma, &epsilon);
51  }
52  {
53  const size_t channels = 4;
54  m_funcPtrRGBa = SimdGaussianBlurInit(width, height, channels, &sigma, &epsilon);
55  }
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 
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  SimdGaussianBlurRun(m_funcPtrRGBa, reinterpret_cast<unsigned char *>(I.bitmap), I.getWidth()*4,
90  reinterpret_cast<unsigned char *>(I_blur.bitmap), I_blur.getWidth()*4);
91  } else {
92  vpImageConvert::split(I, &m_red, &m_green, &m_blue);
93  SimdGaussianBlurRun(m_funcPtrGray, m_red.bitmap, m_red.getWidth(), m_redBlurred.bitmap, m_redBlurred.getWidth());
94  SimdGaussianBlurRun(m_funcPtrGray, m_green.bitmap, m_green.getWidth(), m_greenBlurred.bitmap, m_greenBlurred.getWidth());
95  SimdGaussianBlurRun(m_funcPtrGray, m_blue.bitmap, m_blue.getWidth(), m_blueBlurred.bitmap, m_blueBlurred.getWidth());
96 
97  vpImageConvert::merge(&m_redBlurred, &m_greenBlurred, &m_blueBlurred, NULL, I_blur);
98  }
99  }
100 
101 protected:
102  void * m_funcPtrGray;
103  void * m_funcPtrRGBa;
104  bool m_deinterleave;
106  vpImage<unsigned char> m_green;
107  vpImage<unsigned char> m_blue;
108  vpImage<unsigned char> m_redBlurred;
109  vpImage<unsigned char> m_greenBlurred;
110  vpImage<unsigned char> m_blueBlurred;
111 };
112 #endif // DOXYGEN_SHOULD_SKIP_THIS
113 
123 vpGaussianFilter::vpGaussianFilter(unsigned int width, unsigned int height, float sigma, bool deinterleave)
124  : m_impl(new Impl(width, height, sigma, deinterleave))
125 {
126 }
127 
129 {
130  delete m_impl;
131 }
132 
140 {
141  m_impl->apply(I, I_blur);
142 }
143 
151 {
152  m_impl->apply(I, I_blur);
153 }
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:800
Type * bitmap
points toward the bitmap
Definition: vpImage.h:143
void apply(const vpImage< unsigned char > &I, vpImage< unsigned char > &I_blur)
vpGaussianFilter(unsigned int width, unsigned int height, float sigma, bool deinterleave=false)
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=NULL)
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)
unsigned int getHeight() const
Definition: vpImage.h:188
unsigned int getWidth() const
Definition: vpImage.h:246