资源简介
用来正确读取BMP文件信息:文件头:大小,长宽,颜色数目,关键颜色数目,每像素所用bit数,水平和垂直分辨率,压缩方式等

代码片段和文件信息
clc;clear all;close all;
fid=fopen( ‘t_2.bmp‘‘rb‘);%此处为想要读取的文件名
bfType=fread(fid2);
[s errmsg] = sprintf(‘the file type:%s‘char(bfType));
disp(s);
bfSize=fread(fid4);
fsize=bfSize(4)*256^3+bfSize(3)*256^2+bfSize(2)*256+bfSize(1);
[s errmsg] = sprintf(‘the file size:%d byte‘fsize);
disp(s);
bfOffbits=fread(fid8);
foffset=bfOffbits(8)*256^3+bfOffbits(7)*256^2+bfOffbits(6)*256+bfOffbits(5);
[s errmsg] = sprintf(‘offset to start of pixel data:%d byte‘foffset);
disp(s);
biSize=fread(fid4);
isize=biSize(4)*256^3+biSize(3)*256^2+biSize(2)*256+biSize(1);
[s errmsg] = sprintf(‘the size of infoheader:%d byte‘isize);
disp(s);
infoRead=fread(fid8);
biWidth=infoRead(4)*256^3+infoRead(3)*256^2+infoRead(2)*256+infoRead(1);
biHeight=infoRead(8)*256^3+infoRead(7)*256^2+infoRead(6)*256+infoRead(5);
[s errmsg] = sprintf(‘width: %d \nheight:%d ‘biWidthbiHeight);
disp(s);
infoRead=fread(fid28);
biBitCount=infoRead(4)*256+infoRead(3);
biCompression=infoRead(8)*256^3+infoRead(7)*256^2+infoRead(6)*256+infoRead(5);
biSizeImage=infoRead(12)*256^3+infoRead(11)*256^2+infoRead(10)*256+infoRead(9);
biXPelsPerMeter=infoRead(16)*256^3+infoRead(15)*256^2+infoRead(14)*256+infoRead(13);
biYPelsPerMeter=infoRead(20)*256^3+infoRead(19)*256^2+infoRead(18)*256+infoRead(17);
biCirUsed=infoRead(24)*256^3+infoRead(23)*256^2+infoRead(22)*256+infoRead(21);
biCirImportant=infoRead(28)*256^3+infoRead(27)*256^2+infoRead(26)*256+infoRead(25);
[s errmsg] = sprintf(‘the bit count: %d color count: %d‘...
biBitCount2^biBitCount);
disp(s);
if biCompression==0
disp(‘no compression‘);
else if biCompression==1
disp(‘RLE8 compression‘);
else if biCompression==2
disp(‘RLE4 compression‘);
else disp(‘bit fields compression‘);
end
end
end
if biXPelsPerMeter~=0
[s errmsg] = sprintf(‘horizontal resolution:%d pixels per meter‘biXPelsPerMeter);
disp(s);
else disp(‘default horizontal resulution‘);
end
if biYPelsPerMeter~=0
[s errmsg] = sprintf(‘verticular resolution:%d pixels per meter‘biYPelsPerMeter);
disp(s);
else disp(‘default verticular resulution‘);
end
if biSizeImage~=0
[s errmsg] = sprintf(‘image size: %d‘biSizeImage);
disp(s);
else disp(‘No compression‘);
end
if biCirUsed~=0
[s errmsg] = sprintf(‘%d color actually used‘biCirUsed);
disp(s);
else disp(‘all colors are used‘);
end
if biCirImportant~=0
[s errmsg] = sprintf(‘count of significant colors:%d‘biCirImportant);
disp(s);
else disp(‘all colors are significant‘);
end
skip=mod((4-mod(((biWidth * biBitCount)/8)4))4);
if ((biBitCount==24)&&(foffset==54))
for i=1:biHeight
if biHeight>0
indHeight=biHeight+1-i;
else indHeight=i;
end
for j=1:biWidth
colorRead=fread(fid3);
I(indHeightj1)=colorRead(3);
I(indHeightj2)=colorRead(2);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4011 2009-12-15 21:25 bmpdisplay.m
文件 238134 2001-12-10 15:24 t_2.bmp
----------- --------- ---------- ----- ----
242145 2
- 上一篇:各种调制方式的matlab程序
- 下一篇:空间离散点最小二乘直线拟合matlab代码
相关资源
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论