用-c-语言进行数字图像处理

上传人:第*** 文档编号:61261691 上传时间:2018-11-27 格式:DOC 页数:19 大小:81.50KB
返回 下载 相关 举报
用-c-语言进行数字图像处理_第1页
第1页 / 共19页
用-c-语言进行数字图像处理_第2页
第2页 / 共19页
用-c-语言进行数字图像处理_第3页
第3页 / 共19页
用-c-语言进行数字图像处理_第4页
第4页 / 共19页
用-c-语言进行数字图像处理_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《用-c-语言进行数字图像处理》由会员分享,可在线阅读,更多相关《用-c-语言进行数字图像处理(19页珍藏版)》请在金锄头文库上搜索。

1、 用 c 语言进行数字图像处理 其实,数字图像处理有几步呢?一共三步。第一步,读入图片。第二步,处理图片。第三步,保存图片 。 而第二步主要涉及的是处理图像的算法,所以,我在这里就不多说了。而第一步和第三步是为第二步做 位图文件结构的声明:BMP.h #ifndef BMP_H_INCLUDED #define BMP_H_INCLUDED typedef unsigned short WORD; typedef unsigned long DWORD; typedef long LONG; typedef unsigned char BYTE; typedef struct tagBITMA

2、PFILEHEADER / bmfh WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; BITMAPFILEHEADER; typedef struct tagBITMAPINFOHEADER / bmih DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG

3、 biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant; BITMAPINFOHEADER; typedef struct tagRGBQUAD / rgbq BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; RGBQUAD; typedef struct tagBITMAPINFO BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors1; BITMAPINFO; #endif / BMP_H_INCLUDED 主程序:main.c

4、 #include #include #include #include #include #include #include BMP.h BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih; BYTE *imgData; bool bReadBMFH=false; bool bReadBMIH=false; bool bReadPixel=false; /检查路径是否合法:文件能打开;以 bmp 为后缀名 int CheckFilePath(char *filepath); /读入位图的文件头 int ReadFileHeader(char *filep

5、ath,BITMAPFILEHEADER *bmfh); /打印位图的文件头 void PrintFileHeader(BITMAPFILEHEADER *bmfh); /读入位图的信息头 int ReadInfoHeader(char *filepath,BITMAPINFOHEADER *bmih); /打印位图的信息头 void PrintInfoHeader(BITMAPINFOHEADER *bmih); /创建 8 位位图的调色板 int CreatePalette(RGBQUAD pal); /读入位图的像素数据 int ReadPixelData(char *filepath,

6、BYTE *imgData); /计算每行像素所占的字节数 LONG GetLineBytes(int imgWidth,int bitCount); /打印位图的像素数据 void PrintPixelData(BYTE *imgData,int width,int height,int bitCount); /打印菜单选项 void PrintMenu(); /另存为位图 int SaveAsImage(char *filepath); /显示位图 void ShowImage(char * filepath); /保存文件头 int SaveFileHeader(FILE* fp); /

7、保存信息头 int SaveInfoHeader(FILE* fp); /保存调色板 int SaveColorPalette(FILE *fp); /保存像素数据 int SavePixelData(FILE* fp); int main() char filepath256; char saveasfilepath256; int i; int width; int height; int bitCount; DWORD dwLineBytes; int select; int q=0; system(echo off); system(color 2); printf(-TIMimage

8、-n); printf(Input the path of the BMP file:n); gets(filepath); i=CheckFilePath(filepath); if(i=-1) return -1; do PrintMenu(); scanf(%u,&select); switch(select) case 0: printf(Input the path of the BMP file:n); scanf(%s,filepath); CheckFilePath(filepath); break; case 1: i=ReadFileHeader(filepath,&bmf

9、h); if(i!=-1) printf(Read the file header successfully.n); bReadBMFH=true; break; else printf(Read the file header failed.n); bReadBMFH=false; q=1; break; case 2: i=ReadInfoHeader(filepath,&bmih); if(i!=-1) printf(Read the info header successfully.n); bReadBMIH=true; break; else printf(Read the info

10、 header failed.n); bReadBMIH=false; q=1; break; case 3: if(!bReadBMIH) printf(Please read the info header at first.n); break; height=bmih.biHeight; width=bmih.biWidth; bitCount=bmih.biBitCount; dwLineBytes=GetLineBytes(width,bitCount); imgData=(BYTE*)malloc(dwLineBytes*height*sizeof(BYTE); if(!imgData) printf(Can not allocate memory for the image.n); q=1; break; i=ReadPixelData(filepath,imgData); if(i=-1) printf(Read the pixel data failed.n); bReadPixel=false; q=1; break; else printf(Read the pixel data successfully.n); bReadPixel=true; break; case 4: if(bReadBMFH) PrintFile

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 事务文书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号