|
Krita Source Code Documentation
|
#include <KisFilteredRollingMean.h>
Public Member Functions | |
| void | addValue (qreal value) |
| qreal | filteredMean () const |
| bool | isEmpty () const |
| KisFilteredRollingMean (int windowSize, qreal effectivePortion) | |
Private Attributes | |
| std::vector< qreal > | m_cutOffBuffer |
| qreal | m_effectivePortion |
| qreal | m_rollingSum |
| boost::circular_buffer< qreal > | m_values |
A special class that calculates a rolling mean of the values stream, but filtering out random extreme deviations.
On each step the algorithm sorts the entire sampling window and drops a small portion of the lowest and the highest values. The rest of the values are used to calculate the mean of the window.
Basically, it takes the median and a few surrounding values to calculate the mean.
PS: The actually implementation does a few optimizations. For example, it doesn't sort the entire range. But the idea is the same.
Definition at line 33 of file KisFilteredRollingMean.h.
| KisFilteredRollingMean::KisFilteredRollingMean | ( | int | windowSize, |
| qreal | effectivePortion ) |
Creates a mean accumulator
windowSize is the size of the samples window effectivePortion the portion of the samples window that is used for actual mean calculation. On each side of the sorted range (0.5 * (1.0 - effectivePortion) * windowSize) values are dropped and are not counted for the mean calculation.
Definition at line 16 of file KisFilteredRollingMean.cpp.
| void KisFilteredRollingMean::addValue | ( | qreal | value | ) |
Adds a value for the rolling mean calculation. The complexity of the call is O(1).
Definition at line 24 of file KisFilteredRollingMean.cpp.
References m_rollingSum, m_values, and value().
| qreal KisFilteredRollingMean::filteredMean | ( | ) | const |
Calculates the filtered mean value of the current range. The function is slow, its complexity is O(N) + O(N*log(M)), where N is the size of the rolling window, M is the number of elements dropped from the window (1.0 - effectivePortion) * windowSize).
Definition at line 34 of file KisFilteredRollingMean.cpp.
References KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_cutOffBuffer, m_effectivePortion, m_rollingSum, and m_values.
| bool KisFilteredRollingMean::isEmpty | ( | ) | const |
Returns true if the accumulator has at least some value
Definition at line 87 of file KisFilteredRollingMean.cpp.
References m_values.
|
mutableprivate |
Definition at line 72 of file KisFilteredRollingMean.h.
|
private |
Definition at line 71 of file KisFilteredRollingMean.h.
|
private |
Definition at line 70 of file KisFilteredRollingMean.h.
|
private |
Definition at line 69 of file KisFilteredRollingMean.h.