计算机图像处理实验Word文件下载.docx
- 文档编号:15186236
- 上传时间:2022-10-28
- 格式:DOCX
- 页数:21
- 大小:22.42KB
计算机图像处理实验Word文件下载.docx
《计算机图像处理实验Word文件下载.docx》由会员分享,可在线阅读,更多相关《计算机图像处理实验Word文件下载.docx(21页珍藏版)》请在冰豆网上搜索。
例如:
eztest.bmpresult.bmp108(对test.bmp文件进行二值化处理,阈值为108,处理的结果为result.bmp文件)
hdr.h文件内容:
#ifndef__HDR_H__
#define__HDR_H__
structbmphdr{
charsignature[2];
intsize;
shortreserved[2];
intoffset;
inthdr_size;
intwidth;
intheight;
shortnr_planes;
shortbits_per_pixel;
intcompress_type;
intdata_size;
intresol_hori;
intresol_vert;
intnr_colors;
intimportant_color;
charinfo[1024];
};
structbmphdr*get_header(charfilename[]);
#endif
hdr.c文件内容:
#include<
stdio.h>
memory.h>
#include"
hdr.h"
structbmphdr*get_header(charfilename[])
{
FILE*fp;
structbmphdr*hdr;
fp=fopen(filename,"
rb"
);
if(!
fp){
printf("
Fileopenerrororsuchfiledoesnotexist!
\n"
returnNULL;
}
hdr=(structbmphdr*)malloc(sizeof(structbmphdr));
fread(hdr->
signature,2,1,fp);
if(hdr->
signature[0]!
='
B'
||hdr->
signature[1]!
M'
){
Notabmpfile!
fread(&
hdr->
size,4,1,fp);
reserved,4,1,fp);
offset,4,1,fp);
hdr_size,4,1,fp);
width,4,1,fp);
height,4,1,fp);
nr_planes,2,1,fp);
bits_per_pixel,2,1,fp);
compress_type,4,1,fp);
data_size,4,1,fp);
resol_hori,4,1,fp);
resol_vert,4,1,fp);
nr_colors,4,1,fp);
important_color,4,1,fp);
offset>
54)
fread(&
info,1024,1,fp);
fclose(fp);
returnhdr;
}
bmphdr.c文件内容:
}header;
intmain(intargc,char*argv[])
if(argc!
=2){
Usage:
%s<
filename>
argv[0]);
exit
(1);
fp=fopen(argv[1],"
r"
fread(header.signature,2,1,fp);
if(header.signature[0]!
||header.signature[1]!
header.size,4,1,fp);
fread(header.reserved,4,1,fp);
header.offset,4,1,fp);
header.hdr_size,4,1,fp);
header.width,4,1,fp);
header.height,4,1,fp);
header.nr_planes,2,1,fp);
header.bits_per_pixel,2,1,fp);
press_type,4,1,fp);
header.data_size,4,1,fp);
header.resol_hori,4,1,fp);
header.resol_vert,4,1,fp);
header.nr_colors,4,1,fp);
header.important_color,4,1,fp);
printf("
signature%c%c\n"
header.signature[0],header.signature[1]);
size%d\n"
header.size);
offset%d\n"
header.offset);
hdr_size%d\n"
header.hdr_size);
width%d\n"
header.width);
height%d\n"
header.height);
nr_planes%d\n"
header.nr_planes);
bits_per_pixel%d\n"
header.bits_per_pixel);
compress_type%d\n"
press_type);
data_size%d\n"
header.data_size);
resol_hori%d\n"
header.resol_hori);
resol_vert%d\n"
header.resol_vert);
nr_colors%d\n"
header.nr_colors);
important_color%d\n"
header.important_color);
return0;
二值化程序ez.c文件内容:
stdlib.h>
structbmphdr*hdr;
unsignedchar*bitmap,*to;
charbuf[2048];
inti,j,k,nr_pixels;
FILE*fp,*fpnew;
unsignedg;
=4){
file_from>
<
file_to>
threshold>
hdr=get_header(argv[1]);
hdr)exit
(1);
Fileopenerror!
fseek(fp,hdr->
offset,SEEK_SET);
nr_pixels=hdr->
width*hdr->
height;
bitmap=malloc(nr_pixels);
fread(bitmap,nr_pixels,1,fp);
k=atoi(argv[3]);
to=malloc(nr_pixels);
memset(to,0,nr_pixels);
for(i=0;
i<
nr_pixels;
i++)
to[i]=bitmap[i]>
(unsignedchar)k?
255:
0;
fpnew=fopen(argv[2],"
wb+"
fpnew){
Filecreateerror!
fwrite(hdr-
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 图像 处理 实验