NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
filtering.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2020 Erik Haenel et al.
4
5 This program 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 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef FILTERING_HPP
20#define FILTERING_HPP
21
22#include <utility>
23#include <vector>
24#include <cmath>
25#include <queue>
26#include "../io/file.hpp"
27#include "../utils/tools.hpp"
28#include "../ParserLib/muParserDef.h"
29
30//void showMatrix(const vector<vector<double> >&);
31
32namespace NumeRe
33{
40 {
42 {
47 };
48
50 size_t row;
51 size_t col;
52 double alpha;
53
54 FilterSettings(FilterType _type = FILTER_NONE, size_t _row = 1u, size_t _col = 1u, double _alpha = NAN) : type(_type), row(std::max(_row, 1u)), col(std::max(_col, 1u)), alpha(_alpha)
55 {
56 //
57 }
58 };
59
60
69 inline double pow2(double val)
70 {
71 return val * val;
72 }
73
74
83 inline double pow3(double val)
84 {
85 return val * val * val;
86 }
87
88
97 inline double pow4(double val)
98 {
99 return val * val * val * val;
100 }
101
102
107 using FilterBuffer = std::queue<mu::value_type>;
108 using FilterBuffer2D = std::queue<std::vector<mu::value_type>>;
109
110
116 class Filter
117 {
118 protected:
120 std::pair<size_t, size_t> m_windowSize;
124
125 public:
134 Filter(size_t row, size_t col) : m_type(FilterSettings::FILTER_NONE), m_isConvolution(false)
135 {
136 // This expression avoids that someone tries to
137 // create a filter with a zero dimension.
138 m_windowSize = std::make_pair(std::max(row, 1u), std::max(col, 1u));
139 }
140
144 virtual ~Filter() {}
145
156 virtual double operator()(size_t i, size_t j) const = 0;
157
169 virtual mu::value_type apply(size_t i, size_t j, const mu::value_type& val) const = 0;
170
181 bool isConvolution() const
182 {
183 return m_isConvolution;
184 }
185
195 {
196 return m_type;
197 }
198
207 std::pair<size_t,size_t> getWindowSize() const
208 {
209 return m_windowSize;
210 }
211
221 {
222 return m_buffer;
223 }
224
235 {
236 return m_buffer2D;
237 }
238 };
239
240
248 {
249 private:
250 bool is2D;
251 std::vector<std::vector<double> > m_filterKernel;
252
261 {
262 if (!is2D)
263 is2D = m_windowSize.first > 1 && m_windowSize.second > 1;
264
265 if (!(m_windowSize.first % 2))
266 m_windowSize.first++;
267
268 m_filterKernel = std::vector<std::vector<double> >(m_windowSize.first, std::vector<double>(m_windowSize.second, 0.0));
269
270 double mean_row = m_windowSize.first > 1 ? 0.5 : 0.0;
271 double mean_col = m_windowSize.second > 1 ? 0.5 : 0.0;
272 double sum = 0;
273
274 // Calculate the filter values
275 for (size_t i = 0; i < m_windowSize.first; i++)
276 {
277 for (size_t j = 0; j < m_windowSize.second; j++)
278 {
279 if (sqrt(pow2(i/((double)std::max(1u, m_windowSize.first-1))-mean_row) + pow2(j/((double)std::max(1u, m_windowSize.second-1))-mean_col)) <= 0.5)
280 {
281 m_filterKernel[i][j] = fabs(sqrt(pow2(i/((double)std::max(1u, m_windowSize.first-1))-mean_row) + pow2(j/((double)std::max(1u, m_windowSize.second-1))-mean_col)) - 0.5);
282 sum += m_filterKernel[i][j];
283 }
284 }
285 }
286
287 for (size_t i = 0; i < m_windowSize.first; i++)
288 {
289 for (size_t j = 0; j < m_windowSize.second; j++)
290 {
291 m_filterKernel[i][j] /= sum;
292 }
293 }
294 }
295
296 public:
306 WeightedLinearFilter(size_t row, size_t col, bool force2D = false) : Filter(row, col)
307 {
309 m_isConvolution = true;
310 is2D = force2D;
311
312 createKernel();
313 }
314
319 virtual ~WeightedLinearFilter() override
320 {
321 m_filterKernel.clear();
322 }
323
333 virtual double operator()(size_t i, size_t j) const override
334 {
335 if (i >= m_windowSize.first || j >= m_windowSize.second)
336 return NAN;
337
338 return m_filterKernel[i][j];
339 }
340
353 virtual mu::value_type apply(size_t i, size_t j, const mu::value_type& val) const override
354 {
355 if (i >= m_windowSize.first || j >= m_windowSize.second)
356 return NAN;
357
358 return m_filterKernel[i][j]*val;
359 }
360 };
361
362
367 class GaussianFilter : public Filter
368 {
369 private:
370 std::vector<std::vector<double> > m_filterKernel;
371
379 void createKernel(double sigma)
380 {
381 m_filterKernel = std::vector<std::vector<double> >(m_windowSize.first, std::vector<double>(m_windowSize.second, 0.0));
382
383 double sum = 0.0;
384 double mean_row = (m_windowSize.first - 1) * 0.5;
385 double mean_col = (m_windowSize.second - 1) * 0.5;
386
387 for (size_t i = 0; i < m_windowSize.first; i++)
388 {
389 for (size_t j = 0; j < m_windowSize.second; j++)
390 {
391 m_filterKernel[i][j] = exp(-(pow2(i-mean_row) + pow2(j-mean_col)) / (2*pow2(sigma))) / (2*M_PI*pow2(sigma));
392 sum += m_filterKernel[i][j];
393 }
394 }
395
396 for (size_t i = 0; i < m_windowSize.first; i++)
397 {
398 for (size_t j = 0; j < m_windowSize.second; j++)
399 {
400 m_filterKernel[i][j] /= sum;
401 }
402 }
403 }
404
405 public:
414 GaussianFilter(size_t row, size_t col, double sigma) : Filter(row, col)
415 {
417 m_isConvolution = true;
418
419 createKernel(sigma);
420 }
421
426 virtual ~GaussianFilter() override
427 {
428 m_filterKernel.clear();
429 }
430
440 virtual double operator()(size_t i, size_t j) const override
441 {
442 if (i >= m_windowSize.first || j >= m_windowSize.second)
443 return NAN;
444
445 return m_filterKernel[i][j];
446 }
447
460 virtual mu::value_type apply(size_t i, size_t j, const mu::value_type& val) const override
461 {
462 if (i >= m_windowSize.first || j >= m_windowSize.second)
463 return NAN;
464
465 if (mu::isnan(val))
466 return 0.0;
467
468 // Gaussian is symmetric, therefore the convolution does not
469 // need to be inverted
470 return m_filterKernel[i][j] * val;
471 }
472 };
473
474
481 {
482 private:
483 std::vector<std::vector<double>> m_filterKernel;
484
495 long long int findColumn(const FileView& _view)
496 {
497 std::vector<size_t> vWindowSizes;
498
499 // Decode all contained window sizes
500 for (long long int j = 0; j < _view.getCols(); j++)
501 {
502 vWindowSizes.push_back(StrToInt(_view.getColumnHead(j).substr(0, _view.getColumnHead(j).find('x'))));
503 }
504
505 // Window size is already smaller than the first
506 // available window size
507 if (m_windowSize.first < vWindowSizes.front())
508 {
509 m_windowSize.first = vWindowSizes.front();
510 m_windowSize.second = m_windowSize.first;
511 m_filterKernel = std::vector<std::vector<double> >(m_windowSize.first, std::vector<double>(m_windowSize.second, 0.0));
512
513 return 0;
514 }
515
516 for (long long int j = 0; j < vWindowSizes.size(); j++)
517 {
518 // Found a perfect match?
519 if (m_windowSize.first == vWindowSizes[j])
520 {
521 m_windowSize.second = m_windowSize.first;
522 m_filterKernel = std::vector<std::vector<double> >(m_windowSize.first, std::vector<double>(m_windowSize.second, 0.0));
523
524 return j;
525 }
526
527 // Is there a nearest match? (We assume
528 // ascending order of the window sizes)
529 if (m_windowSize.first > vWindowSizes[j] && j+1 < vWindowSizes.size() && m_windowSize.first < vWindowSizes[j+1])
530 {
531 // If the following fits better, increment the index
532 if (m_windowSize.first - vWindowSizes[j] > vWindowSizes[j+1] - m_windowSize.first)
533 j++;
534
535 m_windowSize.first = vWindowSizes[j];
536 m_windowSize.second = m_windowSize.first;
537 m_filterKernel = std::vector<std::vector<double> >(m_windowSize.first, std::vector<double>(m_windowSize.second, 0.0));
538
539 return j;
540 }
541 else if (m_windowSize.first > vWindowSizes[j] && j+1 == vWindowSizes.size())
542 {
543 m_windowSize.first = vWindowSizes[j];
544 m_windowSize.second = m_windowSize.first;
545 m_filterKernel = std::vector<std::vector<double> >(m_windowSize.first, std::vector<double>(m_windowSize.second, 0.0));
546
547 return j;
548 }
549 }
550
551 return 0;
552 }
553
562 {
563 // Ensure odd numbers
564 if (!(m_windowSize.first % 2))
565 m_windowSize.first++;
566
567 // Create a 2D kernel
568 if (m_windowSize.second > 1)
569 {
570 // Create a file instance
571 GenericFile* _file = getFileByType("<>/params/savitzky_golay_coeffs_2D.dat");
572
573 if (!_file)
574 return;
575
576 // Read the contents and assign it to a view
577 try
578 {
579 _file->read();
580 }
581 catch (...)
582 {
583 delete _file;
584 throw;
585 }
586
587 FileView _view(_file);
588
589 // Find the possible window sizes
590 long long int j = findColumn(_view);
591
592 // First element in the column is the
593 // central element in the matrix
594 m_filterKernel[m_windowSize.first/2][m_windowSize.first/2] = _view.getElement(m_windowSize.first*m_windowSize.first/2, j).real();
595
596 for (long long int i = 0; i < m_windowSize.first*m_windowSize.first/2; i++)
597 {
598 // left part
599 m_filterKernel[m_windowSize.first - 1 - i % m_windowSize.first][i / m_windowSize.first] = _view.getElement(i, j).real();
600 // right part
601 m_filterKernel[i % m_windowSize.first][m_windowSize.first - i / m_windowSize.first - 1] = _view.getElement(i, j).real();
602 // middle column
603 }
604
605 delete _file;
606 return;
607 }
608
609 // Create a 1D kernel
610 m_filterKernel = std::vector<std::vector<double> >(m_windowSize.first, std::vector<double>(m_windowSize.second, 0.0));
611
612 for (size_t i = 0; i < m_windowSize.first; i++)
613 {
614 m_filterKernel[i][0] = (3.0*pow2(m_windowSize.first) - 7.0 - 20.0*pow2((int)i - (int)m_windowSize.first/2)) / 4.0 / (m_windowSize.first * (pow2(m_windowSize.first) - 4.0) / 3.0);
615 }
616 }
617
618 public:
627 SavitzkyGolayFilter(size_t row, size_t col) : Filter(row, col)
628 {
630 m_isConvolution = true;
631
632 createKernel();
633 }
634
639 virtual ~SavitzkyGolayFilter() override
640 {
641 m_filterKernel.clear();
642 }
643
653 virtual double operator()(size_t i, size_t j) const override
654 {
655 if (i >= m_windowSize.first || j >= m_windowSize.second)
656 return NAN;
657
658 return m_filterKernel[i][j];
659 }
660
673 virtual mu::value_type apply(size_t i, size_t j, const mu::value_type& val) const override
674 {
675 if (i >= m_windowSize.first || j >= m_windowSize.second)
676 return NAN;
677
678 if (mu::isnan(val))
679 return 0.0;
680
681 return m_filterKernel[i][j] * val;
682 }
683 };
684
685
692 {
693 private:
694 std::vector<double> m_filterKernel;
695
704 void createKernel(size_t nthDerivative)
705 {
706 // Ensure odd numbers
707 if (!(m_windowSize.first % 2))
708 m_windowSize.first++;
709
710 // Create a 1D kernel
711 m_filterKernel = std::vector<double>(m_windowSize.first, 0.0);
712 double m = m_windowSize.first;
713
714 for (size_t i = 0; i < m_windowSize.first; i++)
715 {
716 double I = (int)i - floor(m/2.0);
717
718 if (nthDerivative == 1)
719 m_filterKernel[i] = 15.0 * (5.0*(3.0*pow4(m) - 18.0*pow2(m) + 31.0)*I - 28.0*(3.0*pow2(m)-7.0)*pow3(I))
720 / (m * (pow2(m) - 1.0)*(3.0*pow4(m) - 39.0*pow2(m) + 108.0));
721 else if (nthDerivative == 2)
722 m_filterKernel[i] = 30.0 * (12.0*m*pow2(I) - m * (pow2(m) - 1.0))
723 / (pow2(m) * (pow2(m) - 1.0) * (pow2(m) - 4.0));
724 else if (nthDerivative == 3)
725 m_filterKernel[i] = 6 * 420.0 * (-(3.0*pow2(m) - 7.0)*I + 20.0*pow3(I))
726 / (m * (pow2(m) - 1.0)*(3.0*pow4(m) - 39.0*pow2(m) + 108.0));
727 else
728 m_filterKernel[i] = 15.0 * (5.0*(3.0*pow4(m) - 18.0*pow2(m) + 31.0)*I - 28.0*(3.0*pow2(m)-7.0)*pow3(I))
729 / (m * (pow2(m) - 1.0)*(3.0*pow4(m) - 39.0*pow2(m) + 108.0));
730 }
731 }
732
733 public:
742 SavitzkyGolayDiffFilter(size_t row, size_t nthDerivative) : Filter(row, 1)
743 {
745 m_isConvolution = true;
746
747 createKernel(nthDerivative);
748 }
749
754 virtual ~SavitzkyGolayDiffFilter() override
755 {
756 m_filterKernel.clear();
757 }
758
768 virtual double operator()(size_t i, size_t j) const override
769 {
770 if (i >= m_windowSize.first)
771 return NAN;
772
773 return m_filterKernel[i];
774 }
775
788 virtual mu::value_type apply(size_t i, size_t j, const mu::value_type& val) const override
789 {
790 if (i >= m_windowSize.first)
791 return NAN;
792
793 if (mu::isnan(val))
794 return 0.0;
795
796 return m_filterKernel[i] * val;
797 }
798 };
799
800
814 inline Filter* createFilter(const FilterSettings& _settings)
815 {
816 switch (_settings.type)
817 {
819 return nullptr;
821 return new WeightedLinearFilter(_settings.row, _settings.col);
823 return new GaussianFilter(_settings.row, _settings.col, (std::max(_settings.row, _settings.col)-1)/(2*_settings.alpha));
825 return new SavitzkyGolayFilter(_settings.row, _settings.col);
826 }
827
828 return nullptr;
829 }
830
831
837 class RetouchRegion : public Filter
838 {
839 private:
840 std::vector<mu::value_type> m_left;
841 std::vector<mu::value_type> m_right;
842 std::vector<mu::value_type> m_top;
843 std::vector<mu::value_type> m_bottom;
844 bool is2D;
845 std::vector<std::vector<double> > m_filterKernel;
848
857 {
858 m_filterKernel = std::vector<std::vector<double> >(m_windowSize.first, std::vector<double>(m_windowSize.second, 0.0));
859
860 if (!is2D)
861 is2D = m_windowSize.first > 1 && m_windowSize.second > 1;
862
863 double mean_row = m_windowSize.first > 1 ? 0.5 : 0.0;
864 double mean_col = m_windowSize.second > 1 ? 0.5 : 0.0;
865
866 // Calculate the filter values
867 for (size_t i = 0; i < m_windowSize.first; i++)
868 {
869 for (size_t j = 0; j < m_windowSize.second; j++)
870 {
871 if (sqrt(pow2(i/((double)std::max(1u, m_windowSize.first-1))-mean_row) + pow2(j/((double)std::max(1u, m_windowSize.second-1))-mean_col)) <= 0.5)
872 {
873 m_filterKernel[i][j] = fabs(sqrt(pow2(i/((double)std::max(1u, m_windowSize.first-1))-mean_row) + pow2(j/((double)std::max(1u, m_windowSize.second-1))-mean_col)) - 0.5);
874 }
875 }
876 }
877 }
878
888 mu::value_type left(size_t i, size_t j) const
889 {
890 if (!is2D)
891 return validize(m_left.front());
892
893 return validize(m_left[i+1]);
894 }
895
905 mu::value_type right(size_t i, size_t j) const
906 {
907 if (!is2D)
908 return validize(m_right.front());
909
910 return validize(m_right[i+1]);
911 }
912
922 mu::value_type top(size_t i, size_t j) const
923 {
924 if (!is2D)
925 return 0.0;
926
927 return validize(m_top[j+1]);
928 }
929
939 mu::value_type bottom(size_t i, size_t j) const
940 {
941 if (!is2D)
942 return 0.0;
943
944 return validize(m_bottom[j+1]);
945 }
946
957 mu::value_type topleft(size_t i, size_t j) const
958 {
959 if (i >= j)
960 return validize(m_left[i-j]);
961
962 return validize(m_top[j-i]);
963 }
964
975 mu::value_type topright(size_t i, size_t j) const
976 {
977 if (i+j <= m_windowSize.second-1)
978 return validize(m_top[i+j+2]); // size(m_top) + 2 == m_order
979
980 return validize(m_right[i+j-m_windowSize.second+1]);
981 }
982
993 mu::value_type bottomleft(size_t i, size_t j) const
994 {
995 if (i+j <= m_windowSize.first-1)
996 return validize(m_left[i+j+2]); // size(m_left) + 2 == m_order
997
998 return validize(m_bottom[i+j-m_windowSize.first+1]);
999 }
1000
1011 mu::value_type bottomright(size_t i, size_t j) const
1012 {
1013 if (i >= j)
1014 return validize(m_bottom[m_windowSize.second-(i-j)+1]); // size(m_bottom) + 2 == m_order
1015
1016 return validize(m_right[m_windowSize.first-(j-i)+1]);
1017 }
1018
1030 {
1031 if (mu::isnan(val))
1032 return m_fallback;
1033
1034 return val;
1035 }
1036
1037 public:
1047 RetouchRegion(size_t _row, size_t _col, const mu::value_type& _dMedian) : Filter(_row, _col)
1048 {
1050 m_isConvolution = false;
1051 m_fallback = _dMedian;
1052 m_invertedKernel = true;
1053 is2D = true;
1054
1055 createKernel();
1056 }
1057
1062 virtual ~RetouchRegion() override
1063 {
1064 m_filterKernel.clear();
1065 }
1066
1076 virtual double operator()(size_t i, size_t j) const override
1077 {
1078 if (i >= m_windowSize.first || j >= m_windowSize.second)
1079 return NAN;
1080
1081 return m_filterKernel[i][j];
1082 }
1083
1096 virtual mu::value_type apply(size_t i, size_t j, const mu::value_type& val) const override
1097 {
1098 if (i >= m_windowSize.first || j >= m_windowSize.second)
1099 return NAN;
1100
1101 if (!is2D)
1102 {
1103 if (m_invertedKernel)
1104 return m_filterKernel[i][j]*val + (1-m_filterKernel[i][j])*(left(i,j) + (right(i,j) - left(i,j))/(m_windowSize.first + 1.0)*(i + 1.0));
1105
1106 return (1-m_filterKernel[i][j])*val + m_filterKernel[i][j]*(left(i,j) + (right(i,j) - left(i,j))/(m_windowSize.first + 1.0)*(i + 1.0));
1107 }
1108
1109 // cross hair: summarize the linearily interpolated values along the rows and cols at the desired position
1110 // Summarize implies that the value is not averaged yet
1111 mu::value_type dAverage = top(i,j) + (bottom(i,j) - top(i,j)) / (m_windowSize.first + 1.0) * (i+1.0)
1112 + left(i,j) + (right(i,j) - left(i,j)) / (m_windowSize.second + 1.0) * (j+1.0);
1113
1114 // Additional weighting because are the nearest neighbours
1115 dAverage /= 2.0;
1116
1117 // Calculate along columns
1118 // Find the diagonal neighbours and interpolate the value
1119 if (i >= j)
1120 dAverage += topleft(i,j) + (bottomright(i,j) - topleft(i,j)) / (m_windowSize.second - fabs(i-j) + 1.0) * (j+1.0);
1121 else
1122 dAverage += topleft(i,j) + (bottomright(i,j) - topleft(i,j)) / (m_windowSize.first - fabs(i-j) + 1.0) * (i+1.0);
1123
1124 // calculate along rows
1125 // Find the diagonal neighbours and interpolate the value
1126 if (i + j <= m_windowSize.first + 1)
1127 dAverage += bottomleft(i,j) + (topright(i,j) - bottomleft(i,j)) / (i+j+2.0) * (j+1.0);
1128 else
1129 dAverage += bottomleft(i,j) + (topright(i,j) - bottomleft(i,j)) / (double)(m_windowSize.first + m_windowSize.second - i - j) * (double)(m_windowSize.first-i);
1130
1131 // Restore the desired average
1132 dAverage /= 6.0;
1133
1134 if (m_invertedKernel)
1135 return (1-m_filterKernel[i][j])*dAverage + m_filterKernel[i][j]*val;
1136
1137 return (1-m_filterKernel[i][j])*val + m_filterKernel[i][j]*dAverage;
1138 }
1139
1151 void setBoundaries(const std::vector<mu::value_type>& left, const std::vector<mu::value_type>& right, const std::vector<mu::value_type>& top = std::vector<mu::value_type>(), const std::vector<mu::value_type>& bottom = std::vector<mu::value_type>())
1152 {
1153 m_left = left;
1154 m_right = right;
1155 m_top = top;
1156 m_bottom = bottom;
1157 }
1158
1172 mu::value_type retouch(size_t i, size_t j, const mu::value_type& val, const mu::value_type& med)
1173 {
1174 if (mu::isnan(val) && !mu::isnan(med))
1175 return 0.5*(apply(i, j, m_fallback) + med);
1176 else if (mu::isnan(val) && mu::isnan(med))
1177 return apply(i, j, m_fallback);
1178
1179 return val;
1180 }
1181 };
1182}
1183
1184
1185
1186#endif // FILTERING_HPP
1187
1188
This is an abstract base class for any type of a data filter. Requires some methods to be implemented...
Definition: filtering.hpp:117
virtual mu::value_type apply(size_t i, size_t j, const mu::value_type &val) const =0
Virtual method for applying the filter to a distinct value. Has to be implemented in all child classe...
virtual double operator()(size_t i, size_t j) const =0
Virtual operator() override. Has to be implemented in the child classes and shall return the kernel v...
Filter(size_t row, size_t col)
Filter base constructor. Will set the used window sizes.
Definition: filtering.hpp:134
FilterSettings::FilterType getType() const
This method returns the type of the current filter as a value of the FilterType enumeration.
Definition: filtering.hpp:194
FilterBuffer2D m_buffer2D
Definition: filtering.hpp:123
bool m_isConvolution
Definition: filtering.hpp:121
FilterBuffer2D & get2DBuffer()
This method returns the internal filtering buffer queue for 2D data to store already smoothed points ...
Definition: filtering.hpp:234
virtual ~Filter()
Empty virtual abstract destructor.
Definition: filtering.hpp:144
FilterSettings::FilterType m_type
Definition: filtering.hpp:119
bool isConvolution() const
This method returns, whether the current filter is a convolution, ie. whether the returned value may ...
Definition: filtering.hpp:181
std::pair< size_t, size_t > m_windowSize
Definition: filtering.hpp:120
FilterBuffer & getBuffer()
This method returns the internal filtering buffer queue to store already smoothed points avoiding lea...
Definition: filtering.hpp:220
FilterBuffer m_buffer
Definition: filtering.hpp:122
std::pair< size_t, size_t > getWindowSize() const
This method returns the window size of the current filter as a std::pair in the order (row,...
Definition: filtering.hpp:207
This class implements a gaussian smoothing or blurring filter.
Definition: filtering.hpp:368
void createKernel(double sigma)
This method will create the filter's kernel for the selected window size.
Definition: filtering.hpp:379
virtual mu::value_type apply(size_t i, size_t j, const mu::value_type &val) const override
Override for the abstract apply method of the base class. Applies the filter to the value at the sele...
Definition: filtering.hpp:460
virtual double operator()(size_t i, size_t j) const override
Override for the operator(). Returns the filter kernel at the desired position.
Definition: filtering.hpp:440
GaussianFilter(size_t row, size_t col, double sigma)
Filter constructor. Will automatically create the filter kernel.
Definition: filtering.hpp:414
std::vector< std::vector< double > > m_filterKernel
Definition: filtering.hpp:370
virtual ~GaussianFilter() override
Filter destructor. Will clear the previously calculated filter kernel.
Definition: filtering.hpp:426
Template class representing a generic file. This class may be specified for the main data type contai...
Definition: file.hpp:68
virtual bool read()=0
Pure virtual declaration of the read access method. Has to be implemented in all derived classes and ...
This class is a facet for an arbitrary GenericFile instance. It can be used to read the contents of t...
Definition: file.hpp:1264
mu::value_type getElement(long long int row, long long int col) const
Returns the value stored at the passed positions. A default constructed mu::value_type object instanc...
Definition: file.hpp:1349
long long int getCols() const
Returns the number of columns in the internally stored GenericFile instance.
Definition: file.hpp:1315
std::string getColumnHead(long long int col) const
Returns the column heading stored for the passed column. Returns an empty string, if the column does ...
Definition: file.hpp:1404
This class is a specialized WeightedLinearFilter used to retouch missing data values.
Definition: filtering.hpp:838
mu::value_type bottomright(size_t i, size_t j) const
This method will return the correct value for the bottomright diagonal interval boundary.
Definition: filtering.hpp:1011
mu::value_type bottom(size_t i, size_t j) const
This method will return the correct value for the bottom interval boundary.
Definition: filtering.hpp:939
mu::value_type retouch(size_t i, size_t j, const mu::value_type &val, const mu::value_type &med)
This method is a wrapper to retouch only invalid values. The default value of invalid values is the m...
Definition: filtering.hpp:1172
void createKernel()
This method will create the filter's kernel for the selected window size.
Definition: filtering.hpp:856
mu::value_type validize(mu::value_type val) const
This method checks, whether the passed value is a valid value and returns it. If it is not,...
Definition: filtering.hpp:1029
std::vector< mu::value_type > m_right
Definition: filtering.hpp:841
mu::value_type m_fallback
Definition: filtering.hpp:846
void setBoundaries(const std::vector< mu::value_type > &left, const std::vector< mu::value_type > &right, const std::vector< mu::value_type > &top=std::vector< mu::value_type >(), const std::vector< mu::value_type > &bottom=std::vector< mu::value_type >())
This method is used to update the internal filter boundaries.
Definition: filtering.hpp:1151
mu::value_type topright(size_t i, size_t j) const
This method will return the correct value for the topright diagonal interval boundary.
Definition: filtering.hpp:975
mu::value_type top(size_t i, size_t j) const
This method will return the correct value for the top interval boundary.
Definition: filtering.hpp:922
virtual ~RetouchRegion() override
Filter destructor. Will clear the previously calculated filter kernel.
Definition: filtering.hpp:1062
std::vector< std::vector< double > > m_filterKernel
Definition: filtering.hpp:845
mu::value_type topleft(size_t i, size_t j) const
This method will return the correct value for the topleft diagonal interval boundary.
Definition: filtering.hpp:957
std::vector< mu::value_type > m_left
Definition: filtering.hpp:840
std::vector< mu::value_type > m_bottom
Definition: filtering.hpp:843
virtual mu::value_type apply(size_t i, size_t j, const mu::value_type &val) const override
Override for the abstract apply method of the base class. Applies the filter to the value at the sele...
Definition: filtering.hpp:1096
mu::value_type left(size_t i, size_t j) const
This method will return the correct value for the left interval boundary.
Definition: filtering.hpp:888
virtual double operator()(size_t i, size_t j) const override
Override for the operator(). Returns the filter kernel at the desired position.
Definition: filtering.hpp:1076
mu::value_type bottomleft(size_t i, size_t j) const
This method will return the correct value for the bottomleft diagonal interval boundary.
Definition: filtering.hpp:993
mu::value_type right(size_t i, size_t j) const
This method will return the correct value for the right interval boundary.
Definition: filtering.hpp:905
std::vector< mu::value_type > m_top
Definition: filtering.hpp:842
RetouchRegion(size_t _row, size_t _col, const mu::value_type &_dMedian)
Filter constructor. Will automatically create the filter kernel.
Definition: filtering.hpp:1047
This class implements a Savitzky-Golay filter for differentiation providing a derivative up to degree...
Definition: filtering.hpp:692
std::vector< double > m_filterKernel
Definition: filtering.hpp:694
void createKernel(size_t nthDerivative)
This method will create the filter's kernel for the selected window size.
Definition: filtering.hpp:704
SavitzkyGolayDiffFilter(size_t row, size_t nthDerivative)
Filter constructor. Will automatically create the filter kernel.
Definition: filtering.hpp:742
virtual mu::value_type apply(size_t i, size_t j, const mu::value_type &val) const override
Override for the abstract apply method of the base class. Applies the filter to the value at the sele...
Definition: filtering.hpp:788
virtual double operator()(size_t i, size_t j) const override
Override for the operator(). Returns the filter kernel at the desired position.
Definition: filtering.hpp:768
virtual ~SavitzkyGolayDiffFilter() override
Filter destructor. Will clear the previously calculated filter kernel.
Definition: filtering.hpp:754
This class implements a Savitzky-Golay filter, which is a polynomial smoothing filter.
Definition: filtering.hpp:481
void createKernel()
This method will create the filter's kernel for the selected window size.
Definition: filtering.hpp:561
virtual double operator()(size_t i, size_t j) const override
Override for the operator(). Returns the filter kernel at the desired position.
Definition: filtering.hpp:653
SavitzkyGolayFilter(size_t row, size_t col)
Filter constructor. Will automatically create the filter kernel.
Definition: filtering.hpp:627
virtual ~SavitzkyGolayFilter() override
Filter destructor. Will clear the previously calculated filter kernel.
Definition: filtering.hpp:639
long long int findColumn(const FileView &_view)
This private member function finds the column, which either fits perfectly or is the nearest possibil...
Definition: filtering.hpp:495
virtual mu::value_type apply(size_t i, size_t j, const mu::value_type &val) const override
Override for the abstract apply method of the base class. Applies the filter to the value at the sele...
Definition: filtering.hpp:673
std::vector< std::vector< double > > m_filterKernel
Definition: filtering.hpp:483
This class implements a weighted linear smoothing filter, which applies something like a "convergent ...
Definition: filtering.hpp:248
std::vector< std::vector< double > > m_filterKernel
Definition: filtering.hpp:251
void createKernel()
This method will create the filter's kernel for the selected window size.
Definition: filtering.hpp:260
virtual ~WeightedLinearFilter() override
Filter destructor. Will clear the previously calculated filter kernel.
Definition: filtering.hpp:319
WeightedLinearFilter(size_t row, size_t col, bool force2D=false)
Filter constructor. Will automatically create the filter kernel.
Definition: filtering.hpp:306
virtual mu::value_type apply(size_t i, size_t j, const mu::value_type &val) const override
Override for the abstract apply method of the base class. Applies the filter to the value at the sele...
Definition: filtering.hpp:353
virtual double operator()(size_t i, size_t j) const override
Override for the operator(). Returns the filter kernel at the desired position.
Definition: filtering.hpp:333
GenericFile * getFileByType(const string &filename)
This function determines the correct class to be used for the filename passed to this function....
Definition: file.cpp:45
std::queue< mu::value_type > FilterBuffer
Typedef for simplifying the usage of the buffer.
Definition: filtering.hpp:107
std::queue< std::vector< mu::value_type > > FilterBuffer2D
Definition: filtering.hpp:108
double pow4(double val)
This function is a simple helper to implement a power of four.
Definition: filtering.hpp:97
Filter * createFilter(const FilterSettings &_settings)
This function creates an instance of the filter specified by the passed FilterSettings structure.
Definition: filtering.hpp:814
double pow2(double val)
This function is a simple helper to implement a power of two.
Definition: filtering.hpp:69
double pow3(double val)
This function is a simple helper to implement a power of three.
Definition: filtering.hpp:83
CONSTCD14 std::enable_if< detail::no_overflow< Period, typenameTo::period >::value, To >::type floor(const std::chrono::duration< Rep, Period > &d)
Definition: date.h:1251
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
bool isnan(const value_type &v)
Definition: muParserDef.h:379
#define M_PI
Definition: resampler.cpp:47
#define max(a, b)
Definition: resampler.cpp:30
int StrToInt(const std::string &)
Converts a string into an integer.
This structure contains the necessary information to create an instance of one of the following filte...
Definition: filtering.hpp:40
FilterSettings(FilterType _type=FILTER_NONE, size_t _row=1u, size_t _col=1u, double _alpha=NAN)
Definition: filtering.hpp:54