pappsomspp
Library for mass spectrometry
filtermorpho.h
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/filers/filtermorpho.h
3  * \date 02/05/2019
4  * \author Olivier Langella
5  * \brief collection of morphological filters
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
10  *
11  * This file is part of the PAPPSOms++ library.
12  *
13  * PAPPSOms++ is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * PAPPSOms++ is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25  *
26  ******************************************************************************/
27 
28 #pragma once
29 
30 #include "filtersuite.h"
31 #include <cstddef>
32 
33 namespace pappso
34 {
35 
36 struct DataPoint;
37 
38 /** @brief base class that apply a signal treatment based on a window
39  */
40 class FilterMorphoWindowBase : public FilterInterface
41 {
42  protected:
43  std::size_t m_half_window_size = 0;
44 
45  virtual double
46  getWindowValue(std::vector<DataPoint>::const_iterator begin,
47  std::vector<DataPoint>::const_iterator end) const = 0;
48 
49  public:
50  FilterMorphoWindowBase(std::size_t half_window_size);
52  virtual ~FilterMorphoWindowBase(){};
53  virtual Trace &filter(Trace &data_points) const override;
54 
55  virtual std::size_t getHalfWindowSize() const;
56 };
57 
58 /** @brief test purpose
59  */
61 {
62 
63  public:
64  FilterMorphoSum(std::size_t half_window_size);
65  FilterMorphoSum(const FilterMorphoSum &other);
66  virtual ~FilterMorphoSum(){};
67  double
68  getWindowValue(std::vector<DataPoint>::const_iterator begin,
69  std::vector<DataPoint>::const_iterator end) const override;
70 };
71 
72 /** @brief transform the trace into its maximum over a window
73  */
75 {
76 
77  public:
78  FilterMorphoMax(std::size_t half_window_size);
79  FilterMorphoMax(const FilterMorphoMax &other);
80  virtual ~FilterMorphoMax(){};
81  double
82  getWindowValue(std::vector<DataPoint>::const_iterator begin,
83  std::vector<DataPoint>::const_iterator end) const override;
84 
85  std::size_t getMaxHalfEdgeWindows() const;
86 };
87 
88 /** @brief transform the trace into its minimum over a window
89  */
91 {
92 
93  public:
94  FilterMorphoMin(std::size_t half_window_size);
95  FilterMorphoMin(const FilterMorphoMin &other);
96  virtual ~FilterMorphoMin(){};
97  double
98  getWindowValue(std::vector<DataPoint>::const_iterator begin,
99  std::vector<DataPoint>::const_iterator end) const override;
100 
101  std::size_t getMinHalfEdgeWindows() const;
102 };
103 
104 /** @brief transform the trace with the minimum of the maximum
105  * equivalent of the dilate filter for pictures
106  */
108 {
109  private:
110  FilterMorphoMax m_filter_max;
111  FilterMorphoMin m_filter_min;
112 
113  public:
114  FilterMorphoMinMax(std::size_t half_window_size);
116  virtual ~FilterMorphoMinMax(){};
117  Trace &filter(Trace &data_points) const override;
118 
119  std::size_t getMinMaxHalfEdgeWindows() const;
120 };
121 
122 /** @brief transform the trace with the maximum of the minimum
123  * equivalent of the erode filter for pictures
124  */
126 {
127  private:
128  FilterMorphoMin m_filter_min;
129  FilterMorphoMax m_filter_max;
130 
131  public:
132  FilterMorphoMaxMin(std::size_t half_window_size);
134  virtual ~FilterMorphoMaxMin(){};
135  Trace &filter(Trace &data_points) const override;
136 
137  std::size_t getMaxMinHalfEdgeWindows() const;
138 };
139 
140 /** @brief anti spike filter
141  * set to zero alone values inside the window
142  */
144 {
145  private:
146  std::size_t m_half_window_size = 0;
147 
148  public:
149  FilterMorphoAntiSpike(std::size_t half_window_size);
151  virtual ~FilterMorphoAntiSpike(){};
152  Trace &filter(Trace &data_points) const override;
153 
154  std::size_t getHalfWindowSize() const;
155 };
156 
157 
158 /** @brief median filter
159  * apply median of y values inside the window
160  */
162 {
163 
164  public:
165  FilterMorphoMedian(std::size_t half_window_size);
167  virtual ~FilterMorphoMedian(){};
168  double
169  getWindowValue(std::vector<DataPoint>::const_iterator begin,
170  std::vector<DataPoint>::const_iterator end) const override;
171 };
172 
173 
174 /** @brief mean filter
175  * apply mean of y values inside the window : this results in a kind of
176  * smoothing
177  */
179 {
180 
181  public:
182  FilterMorphoMean(std::size_t half_window_size);
184  virtual ~FilterMorphoMean(){};
185  double
186  getWindowValue(std::vector<DataPoint>::const_iterator begin,
187  std::vector<DataPoint>::const_iterator end) const override;
188 
189  std::size_t getMeanHalfEdgeWindows() const;
190 };
191 
192 /** @brief compute background of a trace
193  * compute background noise on a trace
194  */
196 {
197  private:
198  FilterMorphoMedian m_filter_morpho_median;
199  FilterMorphoMinMax m_filter_morpho_minmax;
200 
201  public:
202  FilterMorphoBackground(std::size_t median_half_window_size,
203  std::size_t minmax_half_window_size);
205  virtual ~FilterMorphoBackground(){};
206 
207  const FilterMorphoMedian &getFilterMorphoMedian() const;
208  const FilterMorphoMinMax &getFilterMorphoMinMax() const;
209 
210  Trace &filter(Trace &data_points) const override;
211 };
212 } // namespace pappso
pappso::FilterMorphoWindowBase::FilterMorphoWindowBase
FilterMorphoWindowBase(std::size_t half_window_size)
Definition: filtermorpho.cpp:34
pappso::FilterMorphoWindowBase::getWindowValue
virtual double getWindowValue(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end) const =0
pappso::FilterMorphoMedian
median filter apply median of y values inside the window
Definition: filtermorpho.h:177
pappso::FilterMorphoWindowBase
base class that apply a signal treatment based on a window
Definition: filtermorpho.h:56
PMSPP_LIB_DECL
#define PMSPP_LIB_DECL
Definition: exportinmportconfig.h:12
pappso
Definition: aa.cpp:38
pappso::FilterMorphoWindowBase::~FilterMorphoWindowBase
virtual ~FilterMorphoWindowBase()
Definition: filtermorpho.h:68
pappso::FilterMorphoWindowBase::filter
virtual Trace & filter(Trace &data_points) const override
Definition: filtermorpho.cpp:49
filtersuite.h
pappso::FilterMorphoMin
transform the trace into its minimum over a window
Definition: filtermorpho.h:106
pappso::FilterMorphoMax
transform the trace into its maximum over a window
Definition: filtermorpho.h:90
pappso::FilterInterface
generic interface to apply a filter on a trace
Definition: filterinterface.h:55
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:125
pappso::FilterMorphoWindowBase::getHalfWindowSize
virtual std::size_t getHalfWindowSize() const
Definition: filtermorpho.cpp:44
pappso::FilterMorphoMean
mean filter apply mean of y values inside the window : this results in a kind of smoothing
Definition: filtermorpho.h:194
pappso::FilterMorphoMinMax
transform the trace with the minimum of the maximum equivalent of the dilate filter for pictures
Definition: filtermorpho.h:123
pappso::FilterMorphoWindowBase::m_half_window_size
std::size_t m_half_window_size
Definition: filtermorpho.h:59
pappso::FilterMorphoSum
test purpose
Definition: filtermorpho.h:76
pappso::FilterMorphoMaxMin
transform the trace with the maximum of the minimum equivalent of the erode filter for pictures
Definition: filtermorpho.h:141
pappso::FilterMorphoBackground
compute background of a trace compute background noise on a trace
Definition: filtermorpho.h:211
pappso::FilterMorphoAntiSpike
anti spike filter set to zero alone values inside the window
Definition: filtermorpho.h:159