-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmedianFilter.cpp
executable file
·67 lines (63 loc) · 1.47 KB
/
medianFilter.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "medianFilter.h"
void filter( double* array, int n, int filterSize )
{
Mediator<double> mediator( filterSize );
for (int i = 0; i < filterSize/2; i++)
{
mediator.insert( array[0] );
array[i] = mediator.getMedian();
}
int offset = filterSize/2 + (filterSize % 2);
for (int i = 0; i < offset; i++)
{
mediator.insert( array[i] );
}
for (int i = 0; i < n - offset; i++)
{
array[i] = mediator.getMedian();
mediator.insert( array[i + offset] );
}
for (int i = n - offset; i < n; i++)
{
array[i] = mediator.getMedian();
mediator.insert( array[n - 1] );
}
}
void filter( long* array, int n, int filterSize )
{
Mediator<long> mediator( filterSize );
for (int i = 0; i < filterSize/2; i++)
{
mediator.insert( array[0] );
array[i] = mediator.getMedian();
}
int offset = filterSize/2 + (filterSize % 2);
for (int i = 0; i < offset; i++)
{
mediator.insert( array[i] );
}
for (int i = 0; i < n - offset; i++)
{
array[i] = mediator.getMedian();
mediator.insert( array[i + offset] );
}
for (int i = n - offset; i < n; i++)
{
array[i] = mediator.getMedian();
mediator.insert( array[n - 1] );
}
}
void filterEachRow( double* array, int m, int n, int filterSize )
{
for (int i = 0; i < m; i++)
{
filter( array + i*n, n, filterSize );
}
}
void filterEachRow( long* array, int m, int n, int filterSize )
{
for (int i = 0; i < m; i++)
{
filter( array + i*n, n, filterSize );
}
}