求助:C语言图像处理
我用C语言读取一个图片,不处理显示正常。按书上说的提取轮廓,怎么显示不了,请高手帮忙#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
FILE *fp,*fp1,*fp2;
static char cx[9]={0 ,0, 0 //算子系数
, 0 ,1 ,0,
0,0,-1};
static char cy[9]={0 ,0, 0 //算子系数
,0 ,0 ,1,
0,-1,0};
char d[9];
int i,j,dat;
float xx,yy,zz;
unsigned char image_in[256][256]={0};
unsigned char image_out[256][256]={0};
if((fp=fopen("2.jpg","rb"))==NULL)
{
printf("open error");
exit(1);
}
fread(image_in,256,256,fp);//读取
for(i=1;i<255;i++)//提取轮廓
for(j=1;j<255;j++)
{
d[0]=image_in[i-1][j-1];
d[1]=image_in[i-1][j];
d[2]=image_in[i-1][j+1];
d[3]=image_in[i][j-1];
d[4]=image_in[i][j];
d[5]=image_in[i][j+1];
d[6]=image_in[i+1][j-1];
d[7]=image_in[i+1][j];
d[8]=image_in[i+1][j+1];
xx=(float)(d[0]*cx[0]+d[1]*cx[1]+d[2]*cx[2]+d[3]*cx[3]+
d[4]*cx[4]+d[5]*cx[5]+d[6]*cx[6]+d[7]*cx[7]+d[8]*cx[8]);
yy=(float)(d[0]*cy[0]+d[1]*cy[1]+d[2]*cy[2]+d[3]*cy[3]+
d[4]*cy[4]+d[5]*cy[5]+d[6]*cy[6]+d[7]*cy[7]+d[8]*cy[8]);
zz=(float)(5*sqrt(xx*xx+yy*yy));
dat=(int)zz;
if(dat>255) dat=255;
image_out[i][j]=(char)dat;
}
fp1=fopen("new.jpg","wb");
fp2=fopen("old.jpg","wb");
fwrite(image_out,256,256,fp1);//显示轮廓
fwrite(image_in,256,256,fp2);//显示原来的图片
fclose(fp);
fclose(fp1);
fclose(fp2);
return 0;
}