如何实现滤波算法,请大神看一下程序,指导一下
#include <stdio.h>#include <dos.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <conio.h>
#include <process.h>
#include <io.h>
#include <time.h>
int ReadImage(char *FileName, int *Row, int *Col,unsigned char *Image, char *Fheadg, char *Pallette);
int SaveImage(char *FileName, int Row, int Col, char *Fheadg, char *Pallette,unsigned char *Image);
void main()
{
unsigned char *Image;
char Fheadg[54],Pallette[1024];
int Row,Col;
Image=(unsigned char *)calloc (720*720,sizeof(unsigned char));
if (!ReadImage("E:\\zihua.bmp",&Row,&Col,Image,Fheadg,Pallette))
{ printf("The file %s does not exist!\n","image");
exit(0);
}
SaveImage("E:\\zihualb.bmp",Row,Col,Fheadg,Pallette,Image);
printf(" ok!\n ");
free(Image);
}
int ReadImage(char *FileName, int *Row, int *Col,unsigned char *Image, char *Fheadg, char *Pallette)
{
long Index;
int k,i,j;
FILE *ImageDataFile;
if((ImageDataFile=fopen(FileName,"rb"))==NULL) return(0);
for (i=0;i<54;i++) Fheadg[i]=fgetc(ImageDataFile);
*Col=Fheadg[19]*256+Fheadg[18];
*Row=Fheadg[23]*256+Fheadg[22];
for (i=0;i<1024;i++) Pallette[i]=fgetc(ImageDataFile);
k=(*Col)*3%4; if (k==4) k=0;
Index=0;
for (i=0;i<*Row;i++)
{ for (j=0;j<*Col;j++) Image[Index++]=fgetc(ImageDataFile);
for (j=1;j<=k;j++) fgetc(ImageDataFile);
}
fclose(ImageDataFile); return(1);
}
int SaveImage(char *FileName, int Row, int Col, char *Fheadg, char *Pallette,unsigned char *Image)
{ long Index;
FILE *ImageDataFile;
int i,j,k;
k=Col*3%4; if (k==4) k=0;
if((ImageDataFile=fopen(FileName,"wb"))==NULL) return(0);
for(i=0;i<54;i++) fputc(Fheadg[i],ImageDataFile);
for(i=0;i<1024;i++) fputc(Pallette[i],ImageDataFile);
Index=0;
for (i=0;i<Row;i++)
{ for (j=0;j<Col;j++,Index++) fputc(Image[Index],ImageDataFile);
for (j=1;j<=k;j++) fputc(0,ImageDataFile);
}
fclose(ImageDataFile);
return(1);
}