forked from nowox/moving-median
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_medfilt.c
44 lines (36 loc) · 994 Bytes
/
test_medfilt.c
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
39
40
41
42
43
44
/**
* Example of moving median.
*/
#include <stdio.h>
#include <stdlib.h>
#include "medfilt.h"
static void kernel2str(MedfiltData *data)
{
printf("[ ");
for (size_t i = 0; i < data->length; i++) {
printf("%g ", data->kernel[i].sorted->value);
}
printf("]");
}
static void display(MedfiltData *data,
size_t i, float in, float min, float mid, float max)
{
printf("u[%zu] = %g -> min=%g mid=%g max=%g kernel=", i, in, min, mid, max);
kernel2str(data);
printf("\n");
}
#define KERNEL (5)
#define NAN (0./0.)
int main(void)
{
const float in[] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3 };
MedfiltData data;
MedfiltNode nodes[KERNEL];
medfilt_init(&data, nodes, KERNEL, NAN);
for (size_t i = 0; i < sizeof(in) / sizeof(in[0]); i++) {
float min, mid, max;
medfilt(&data, in[i], &mid, &min, &max);
display(&data, i, in[i], min, mid, max);
}
return EXIT_SUCCESS;
}