blob: 1999185c331984410cd92309921c6d11b5845d8e (
plain)
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
|
// See LICENSE for license details.
//**************************************************************************
// Median filter (c version)
//--------------------------------------------------------------------------
void median( int n, int input[], int results[] )
{
int A, B, C, i;
// Zero the ends
results[0] = 0;
results[n-1] = 0;
// Do the filter
for ( i = 1; i < (n-1); i++ ) {
A = input[i-1];
B = input[i];
C = input[i+1];
if ( A < B ) {
if ( B < C )
results[i] = B;
else if ( C < A )
results[i] = A;
else
results[i] = C;
}
else {
if ( A < C )
results[i] = A;
else if ( C < B )
results[i] = B;
else
results[i] = C;
}
}
}
|