matlab3x3编写均值滤波处理,c语言进行图像均值滤波程序,有问题

#include

#include

#define IMAGE_SIZE_ROW 256

#define IMAGE_SIZE_COL 256

unsigned char origin_image[IMAGE_SIZE_ROW][IMAGE_SIZE_ROW];

unsigned char result_image[IMAGE_SIZE_ROW][IMAGE_SIZE_ROW];

void FILT33(void *I_image,void *O_image,int size_x,int size_y,float eps);

main(int argc,char *argv[])

{

FILE *I_file,*O_file;

char origin_image_file_name[80];

char result_image_file_name[80];

int i;

float eps=0.5;

I_file=fopen("D:\cell.tif","rb");

if(I_file==NULL)

{   perror("printf program error\n");

printf("error");exit(0);   }

for(i=0;i

fread(origin_image[i],sizeof(unsigned char),IMAGE_SIZE_COL,I_file);

FILT33(origin_image,result_image,IMAGE_SIZE_ROW,IMAGE_SIZE_COL,eps);

fclose(I_file);

}

void FILT33(void *I_image,void *O_image,int size_x,int size_y,float eps)

// 3x3 smoothing function

/*arguments:

I_image  --> input image pointer

I_image  --> output image pointer

size_x,size_y   --> image size in both dimensions(row,col)

eps  -->difference tolerence  */

{

int i,j,ia1,im1,ja1,jm1;

float mean_value,gmax,difference;

unsigned char *ptr1,*ptr2;

ptr1=(unsigned char  *)I_image;

ptr2=(unsigned char  *)O_image;

for(i=0;i

{

printf("*");

for(j=0;j

{

ia1=(i+1>size_x-1)?size_x-1:i+1;//get i+1

ja1=(j+1>size_y-1)?size_y-1:j+1;//get j+1

im1=(i-1<0)?0:i-1;//get i-1

im1=(j-1<0)?0:j-1;//get j-1

//calculate 8-neibourhood mean value

mean_value=ptr1[im1*size_y+jm1]+ptr1[im1*size_y+j]+ptr1[im1*size_y+ja1]

+ptr1[i*size_y+jm1]+ptr1[i*size_y+ja1]

+ptr1[ia1*size_y+jm1]+ptr1[ia1*size_y+j]+ptr1[ia1*size_y+ja1];

mean_value=mean_value/8;

//if the difference between mean_value and f(i,j) is greater than ""eps""

//then nochange;else f(i,j) is replaced by mean_value

difference=ptr1[i*size_y+j]-mean_value;

difference=(difference>0)?difference:0-difference;

if(difference

else ptr2[i*size_y+j]=ptr1[i*size_y+j];

}

}

}

我改过了,代码直接插入的,麻烦看下,谢谢了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值