-
Notifications
You must be signed in to change notification settings - Fork 3
/
medfilt.h
38 lines (35 loc) · 1.47 KB
/
medfilt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Moving Median Filter.
* @author CHEVALLIER Yves <[email protected]>
*
* This algorithm is iterative. Each call will compute the next point.
* In the example below, the kernel has a size of 3. Notice that the
* values in the kernel are alway sorted. The left value is therefore
* the minimum in the kernel, the center value is the median and the
* right value is the maximum value.
*
* Input data: 0 1 2 5 4 8 3
* Kernel: |0 0 0| . (min=0, med=0, max=0)
* |0 0 0| . (min=0, med=0, max=0)
* |0 0 1| . (min=0, med=0, max=1)
* |0 1 2| . (min=0, med=1, max=2)
* |1 2 5| . (min=1, med=2, max=5)
* |2 4 5| . (min=2, med=4, max=5)
* |4 5 8|. (min=4, med=5, max=8)
* |3 4 8| (min=3, med=4, max=8)
*/
#pragma once
#include <stdlib.h>
typedef struct MedfiltNode {
float value;
size_t index; // Node index in the sorted table
struct MedfiltNode* parent;
struct MedfiltNode* sorted;
} MedfiltNode;
typedef struct MedfiltData {
MedfiltNode *kernel; // Working filter memory
MedfiltNode *oldest; // Reference to the oldest value in the kernel
size_t length; // Number of nodes
} MedfiltData;
void medfilt_init(MedfiltData *data, MedfiltNode *nodes, size_t length, float init);
void medfilt(MedfiltData *data, float input, float *median, float *min, float *max);