按照:中值滤波的改进算法 - 游戏者 - 博客园的思路
取中值时半径为三,改进后比一般bfptr算法快20倍以上
以下代码模拟3e7次运算并输出时间,时间在400ms内
#include "bits/stdc++.h"
using namespace std;
#define num_type int
num_type a[9],Max1, Max2, Max3, Med1, Med2, Med3, Min1, Min2, Min3, Min_of_Max, Med_of_Med, Max_of_Min, Med_of_nine;
int find_Max(num_type Max1,num_type Max2,num_type Max3)
{
if (Max1 <= Max2) {
if (Max3 <= Max1)return Max3;
else return Max1;
} else {
if (Max3 <= Max2)return Max3;
else return Max2;
}
}
int find_Min(num_type Min1,num_type Min2,num_type Min3)
{
if (Min1 >= Min2) {
if (Min3 >= Min1)return Min3;
else return Min1;
} else {
if (Min3 >= Min2)return Min3;
else return Min2;
}
}
int find_Med(num_type Med1,num_type Med2,num_type Med3)
{
if(Med1>=Med2)
{
if(Med3>=Med1)return Med1;
else if(Med3>=Med2)return Med3;
else return Med2;
} else{
if(Med3>=Med2)return Med2;
else if(Med3>=Med1)return Med3;
else return Med1;
}
}
void three_sort(num_type a,num_type b,num_type c,num_type *Max,num_type *Med,num_type *Min)
{
if(a>b)
{
if(c>a)*Max=c,*Med=a,*Min=b;
else if(c>b)*Max=a,*Med=c,*Min=b;
else *Max=a,*Med=b,*Min=c;
}
else
if(c>b)*Max=c,*Med=b,*Min=a;
else if(c>a)*Max=b,*Med=c,*Min=a;
else *Max=b,*Med=a,*Min=c;
}
int main() {
srand((int)time(0));
double begin,end;
while(1){
for (int i = 0; i < 9; i++)
a[i] =rand()%100;
begin = clock();
for (int j = 0; j < 3e7; j++) {
three_sort(a[0],a[1],a[2],&Max1,&Med1,&Min1);
three_sort(a[3],a

本文探讨了一种中值滤波器的改进算法,该算法在处理3x3窗口时,相比于普通BFPtr算法能提升20倍以上的速度。通过模拟3e7次运算并在400毫秒内完成,验证了算法的高效性。进一步的优化将每次最多比较次数减少到17次,并利用图像处理库进行验证,理论上可在150毫秒内完成3e7次计算。代码示例展示了算法的具体实现和在图像去噪中的应用。
最低0.47元/天 解锁文章
1667

被折叠的 条评论
为什么被折叠?



