图片处理(三)之高斯平滑

本文介绍了一段使用C语言实现的高斯平滑图像处理代码,通过邻近像素点的RGB值加权平均,降低色差,实现图片平滑。程序读取.raw格式文件,对图片进行处理,并输出新的.raw文件。处理方式为1,1,4,1,1的权重分配,分别处理原像素点及周围像素点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本代码主要工作是对图片的数据进行高斯平滑处理。高斯平滑有另一种意思叫“低通滤波”,即LPF,一张图片针对色差进行研究,当色差比较大的地方,便是高频信号较强的地方,色差越大,高频信号越强。

根据这现象,可想采用相邻的像素点三色度平均或均分的方式,降低高频强度,使图片变得更平滑。

本次研究,采用1,1,4,1,1的方式进行均分,针对一个原像点,原像素点占0.5,上下左右各占0.125。

|  0 |  1  | 0  |

|  1 |  4  | 1  |

|  0 |  1  | 0  |

 

实现代码如下:

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<math.h>

 

 

#define           ADD                  0

#define          SUB                   1

#define           MUL                  2

#define           DIV                    3

 

#define           Y_ADD                0

#define      Y_SUB                 1

 

#define         CUR_POS(x,y,width)           ((y)*width+(x))    

#define         X_POS(pos)                        ((pos)%PicWidth)

#define         Y_POS(pos)                        ((pos)/PicWidth)

 

#define           RANGE(x)            (x<0?0:(x>255?255:x))

 

 

//---------------picattribute----------------------    

unsignedint PicWidth;

unsignedint PicHeight;       

//----------------functions---------------------------

voidGraphBrightHandle(unsigned char *src, unsigned char *dest, int size, int type,double num);

voidGraphLPFHandle(unsigned char *src, unsigned char *dest, unsigned int Width,unsigned int Height);

 

 

//---------------------main------------------------

intmain(int argc,char** argv)

{

    int nErrorCode=0;                                               

    FILE *fin;                                                  

    FILE *fout_Bright;

    FILE *fout_LPF;

      

    char szInFilename[256];                                     

    char szOutFilename[256]; 

                          

    if(argc>=2)                                                 

    {                                                           

        strcpy(szInFilename ,argv[1]);                                                 

    }                                                           

    else                                                        

    {                                                            

           strcpy(szInFilename, "44.raw");                                            

    }                                                                                      &nb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值