Skip to content

Commit af6148d

Browse files
committed
Add O(1)_MinMaxFilter.cpp
1 parent 85f40f5 commit af6148d

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const int maxn = 110;
2+
deque <int> U, L;
3+
int maxval[maxn], minval[maxn];
4+
5+
int main(){
6+
int a[10] = {0, 1, 9, 8, 2, 3, 7, 6, 4, 5};
7+
int w = 3;
8+
for(int i = 1; i < 10; i++){
9+
if(i >= w){
10+
maxval[i - w] = a[U.size() > 0 ? U.front() : i-1];
11+
minval[i - w] = a[L.size() > 0 ? L.front() : i-1];
12+
}
13+
if(a[i] > a[i-1]){
14+
L.push_back(i - 1);
15+
if(i == w + L.front()) L.pop_front();
16+
while(U.size() > 0){
17+
if(a[i] <= a[U.back()]){
18+
if(i == w + U.front()) U.pop_front();
19+
break;
20+
}
21+
U.pop_back();
22+
}
23+
}
24+
else{
25+
U.push_back(i-1);
26+
if(i == w + U.front()) U.pop_front();
27+
while(L.size() > 0){
28+
if(a[i] >= a[L.back()]){
29+
if(i == w + L.front()) L.pop_front();
30+
break;
31+
}
32+
L.pop_back();
33+
}
34+
}
35+
}
36+
maxval[10 - w] = a[U.size() > 0 ? U.front() : 9];
37+
minval[10 - w] = a[L.size() > 0 ? L.front() : 9];
38+
for(int i = 0; i <= 10 - w; i++){
39+
printf("Min index %d is: %d\n", i, minval[i]);
40+
printf("Max index %d is: %d\n", i, maxval[i]);
41+
}
42+
return 0;
43+
}

Algorithm optimization/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
- Huang_Fast_MedianBlur.cpp 利用直方图实现快速中值滤波算法,算法原理:https://blog.csdn.net/just_sort/article/details/87994573
99
- speed_exp.cpp 在神经网络权值较小的情况下的快速exp算法,算法原理:https://blog.csdn.net/just_sort/article/details/88128200
1010
- fast_meanFilter.cpp 积分图实现o(1)均值滤波,代码来自ImageShop,算法原理:http://www.cnblogs.com/Imageshop/p/6219990.html
11-
- IntegralGraphforMeanFiltering.cpp 积分图实现O(1)均值滤波,算法原理:http://www.cnblogs.com/Imageshop/p/6219990.html
11+
- IntegralGraphforMeanFiltering.cpp 积分图实现O(1)均值滤波,算法原理:http://www.cnblogs.com/Imageshop/p/6219990.html
12+
- O(1)_MinMaxFilter.cpp 《STREAMING MAXIMUM-MINIMUM FILTER USING NO MORE THAN THREE COMPARISONS PER ELEMENT
13+
》论文复现,O(1)实现最大最小值滤波算法,算法原理:https://blog.csdn.net/just_sort/article/details/89424709

0 commit comments

Comments
 (0)