# 图像处理之均值滤波介绍及C算法实现

2022年11月23日
0 收藏 691 点赞 2,162 浏览 2830 个字

# 1 均值滤波介绍

## 2 均值滤波算法实现(C语言)

` // junzhilvbo.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "stdlib.h" #include "string.h" #define DATA_X 256      //数字图像水平像素个数 #define DATA_Y 256      //数字图像竖直像素个数 void OpenFile(const char *cFilePath , int nOriginalData[DATA_Y][DATA_X]) {     printf("正在获取数据......\n");     FILE *fp ;     fp = fopen(cFilePath , "r");     if(NULL == fp)     {         printf("open file failed! \n");         return ;     }     unsigned char *pData = (unsigned char *)malloc(sizeof(unsigned char)*DATA_X*DATA_Y);     if(NULL == pData)     {         printf("memory malloc failed!\n");         return ;     }     fread(pData , sizeof(unsigned char)*DATA_X*DATA_Y ,  , fp);     int count_x =  ;     int count_y =  ;     for(;count_y < DATA_Y ; count_y++)     {         for(; count_x < DATA_X ;count_x++)         {             nOriginalData[count_y][count_x] = pData[count_y*DATA_Y+count_x];         }     }     free(pData);     fclose(fp);         return ; } void SaveFile(const char *cFilePath , int nResultData[DATA_Y][DATA_X]) {     printf("正在保存数据......\n");     int count_x,count_y;     FILE *fp ;     fp = fopen(cFilePath , "w");     if(NULL == fp)     {         printf("open file failed! \n");         return ;     }     for(count_y=;count_y<DATA_Y;count_y++)     {         for(count_x=;count_x<DATA_X;count_x++)         {             fwrite(&nResultData[count_y][count_x],,,fp);         }     }     fclose(fp);     printf("文件保存成功! \n");     return ; } bool JunZhiLvBo(const int nOriginalData[DATA_Y][DATA_X], int nResultData[DATA_Y][DATA_X]) {     printf("正在进行均值滤波......\n");     int count_x ,count_y ;     /*3*3模版滤波计算，不计算边缘像素*/     for(count_y =  ; count_y < DATA_Y ; count_y++)     {         for(count_x =  ; count_x < DATA_X ;count_x++)         {             nResultData[count_y][count_x] = (int)((nOriginalData[count_y-][count_x-]+                                                    nOriginalData[count_y-][count_x]  +                                                    nOriginalData[count_y-][count_x+]+                                                    nOriginalData[count_y][count_x-]  +                                                    nOriginalData[count_y][count_x]    +                                                    nOriginalData[count_y][count_x+]  +                                                    nOriginalData[count_y+][count_x-]+                                                    nOriginalData[count_y+][count_x]  +                                                    nOriginalData[count_y+][count_x+])/);         }     }     /*对四个边缘直接进行赋值处理*/     for(count_x=;count_x<DATA_X;count_x++)                                        //水平边缘像素等于原来像素灰度值     {         nResultData[][count_x]=nOriginalData[][count_x];         nResultData[DATA_Y-][count_x]=nOriginalData[DATA_Y-][count_x];     }     for(count_y=;count_y<DATA_Y-;count_y++)                                     //竖直边缘像素等于原来像素灰度值     {         nResultData[count_y][]=nOriginalData[count_y][];         nResultData[count_y][DATA_X-]=nOriginalData[count_y][DATA_X-];     }     return true ; } int _tmain(int argc, _TCHAR* argv[]) {     int nOriginalData[DATA_Y][DATA_X]; //保存原始图像灰度值     int nResultData[DATA_Y][DATA_X];   //保存滤波后的灰度值     memset(nOriginalData,,sizeof(nOriginalData));  //初始化数组     memset(nResultData,,sizeof(nResultData));                                          char cOpenFilePath[] = "Lena.raw";                                           //图像文件路径     OpenFile(cOpenFilePath,nOriginalData);                               if(!JunZhiLvBo(nOriginalData,nResultData))                                   //滤波计算     {         printf("操作失败!\n");         return ;     }     char cSaveFilePath[] = "Result.raw";                                        //文件保存路径     SaveFile(cSaveFilePath,nResultData);      return ; }`

## 3 均值滤波算法效果对比

python开发_常用的python模块及安装方法

Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接：http://www.codeforces.com/contest/660/problem/CDes…

zengkefu@server1:/usr/src\$ uname -aLinux server1 4.10.0-19-generic #21…

Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式，并且由于涉及到要把拍到的照片显…

Struts的使用

400-888-8888

ceotheme@ceo.com