-
大小: 2.6MB文件类型: .zip金币: 2下载: 0 次发布日期: 2023-11-07
- 语言: Matlab
- 标签: pbm/pgm/ppm Matlab
资源简介
pbm/pgm/ppm图片的读写函数和测试程序(Matlab)

代码片段和文件信息
function [ IMG ] = imread_pxm( filename )
% filename : the name of .ppm/.pgm/.pbm file (in ASCII/Binary mode)
% This function read .ppm/.pgm/.pbm file and store the image data into variable IMG
fid = fopen(filename ‘rb‘); % open .ppm file in binary mode
p = fread(fid 1 ‘*char‘); % read the char ‘p‘
pinfo = fgetl(fid); % read the head information of the image
info = str2num(pinfo); % convert the info of image into number
[ptype m n] = deal(info(1)info(2)info(3));
% ptype : the type of the image (p1..p6)
% n m : the display resolution
if (ptype ~= 1)&&(ptype ~= 4) % range : the range of pixels‘ value
range = info(4);
else range = 1;
end
if info(1) <= 3 % the image is stored in ASCII mode
if ptype == 3 % .ppm(RGB) & ASCII
for i = 1:n
for j = 1:m
for k = 1:3
num = 0;
ch = fread(fid 1 ‘uint8‘);
while (~feof(fid))&&(ch ~= 32)&&(ch ~= 10) % read the value of image in ASCII mode
num = num * 10 + ch - 48;
ch = fread(fid 1 ‘uint8‘);
end
IMG(i j k) = uint8(num); % update the value of return var
end
end
end
else % .pbm/.pgm & ASCII
for i = 1:n
for j = 1:m
num = 0;
ch = fread(fid 1 ‘uint8‘);
while (~feof(fid))&&(ch ~= 32)&&(ch ~= 10) % read the value of image in ASCII mode
num = num * 10 + ch - 48;
ch = fread(fid 1 ‘uint8‘);
end
if ptype == 2 % process .pgm file
IMG(i j) = uint8(num); % update the value of return var
elseif ptype == 1
IMG(ij) = logical(1 - num); % process .pbm file
end
end
end
end
else % the image is stored in binary mode
if ptype == 6 % .ppm(RGB) & binary
for i = 1:n
for j = 1:m
for k = 1:3
ch = fread(fid 1 ‘uint8‘);
IMG(i j k) = uint8(ch); % update the value of return var
end
end
end
elseif ptype == 5 % .pgm & binary
for i = 1:n
for j = 1:m
ch = fread(fid 1 ‘uint8‘);
IMG(i j) = uint8(ch); % update the value of return var
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-03-04 23:21 程序\
文件 74948 2016-03-02 16:18 程序\greens.jpg
文件 18911 2016-03-03 10:27 程序\greens.pbm
文件 150015 2016-03-03 10:27 程序\greens.pgm
文件 450015 2016-03-02 23:54 程序\greens.ppm
文件 300010 2016-03-03 10:27 程序\greens1.pbm
文件 470765 2016-03-03 10:27 程序\greens1.pgm
文件 1392328 2016-03-02 23:53 程序\greens1.ppm
文件 4495 2016-03-04 00:04 程序\imread_pxm.m
文件 4327 2016-03-04 23:07 程序\imwrite_pxm.m
文件 244 2016-03-02 23:54 程序\jpg2ppm.m
文件 300011 2016-03-04 23:18 程序\p1.pbm
文件 150015 2016-03-04 23:18 程序\p1.pgm
文件 470766 2016-03-04 23:18 程序\p2.pgm
文件 1392329 2016-03-04 23:18 程序\p3.ppm
文件 18911 2016-03-04 23:18 程序\p4.pbm
文件 150015 2016-03-04 23:18 程序\p5.pgm
文件 450015 2016-03-04 23:18 程序\p6.ppm
文件 903 2016-03-04 23:25 程序\Readme.txt
文件 1442 2016-03-04 00:11 程序\test_imread_pxm.m
文件 1500 2016-03-04 23:18 程序\test_imwrite_pxm.m
文件 45668 2016-03-04 23:21 程序\tmp.jpg
相关资源
- 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
评论
共有 条评论