30 #ifndef FILTERS_MEDIAN_HPP_
31 #define FILTERS_MEDIAN_HPP_
49 #define ELEM_SWAP(a,b) { elem_type t=(a);(a)=(b);(b)=t; }
66 template <
typename elem_type>
89 #define median(a,n) kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
113 virtual bool update(
const T& data_in, T& data_out);
126 template <
typename T>
128 number_of_observations_(0)
133 template <
typename T>
139 template <
typename T>
145 fprintf(stderr,
"Error: MedianFilter was not given params.\n");
148 number_of_observations_ = no_obs;
151 temp_storage_.resize(number_of_observations_);
156 template <
typename T>
162 data_storage_->push_back(data_in);
165 unsigned int length = data_storage_->size();
168 for (uint32_t row = 0; row < length; row ++)
170 temp_storage_[row] = (*data_storage_)[row];
172 data_out =
median(&temp_storage_[0], length);
180 template <
typename T>
197 virtual bool update(
const std::vector<T>& data_in, std::vector<T>& data_out);
210 template <
typename T>
212 number_of_observations_(0)
217 template <
typename T>
223 template <
typename T>
229 fprintf(stderr,
"Error: MultiChannelMedianFilter was not given params.\n");
232 number_of_observations_ = no_obs;
234 temp.resize(this->number_of_channels_);
236 temp_storage_.resize(number_of_observations_);
241 template <
typename T>
245 if (data_in.size() != this->number_of_channels_ || data_out.size() != this->number_of_channels_)
250 data_storage_->push_back(data_in);
253 unsigned int length = data_storage_->size();
256 for (uint32_t i = 0; i < this->number_of_channels_; i++)
258 for (uint32_t row = 0; row < length; row ++)
260 temp_storage_[row] = (*data_storage_)[row][i];
262 data_out[i] =
median(&temp_storage_[0], length);
270 #endif// FILTERS_MEDIAN_HPP_