中值滤波改进

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

按照:中值滤波的改进算法 - 游戏者 - 博客园的思路

取中值时半径为三,改进后比一般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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LoseHu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值