Files
firmware/src/Filters/median3.hpp
2024-10-29 09:29:11 +07:00

20 lines
542 B
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// быстрый медианный фильтр 3-го порядка
#pragma once
#ifndef _GMedian3_h
#define _GMedian3_h
template < typename TYPE >
class GMedian3 {
public:
TYPE filtered(TYPE value) { // возвращает фильтрованное значение
buf[_counter] = value;
if (++_counter > 2) _counter = 0;
return (max(buf[0], buf[1]) == max(buf[1], buf[2])) ? max(buf[0], buf[2]) : max(buf[1], min(buf[0], buf[2]));
}
private:
TYPE buf[3];
uint8_t _counter = 0;
};
#endif