-
大小: 2.6MB文件类型: .zip金币: 1下载: 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实现VQ说话人识别系统.zip
- 基于MATLAB数字图像处理的实现和仿真
-
matlab simuli
nk simevent 建模入门 - 数字图像处理实验报告北科大 matlab
- Matlab帧内/帧间预测
- 基于Matlab和FPGA的FIR数字滤波器设计及
- Matlab_R2009a_V7.8.0汉化包
- 基于HMM的姿势识别 matlab代码
- matlab r2013b crack
- matlab学习手册
- 西交大模式识别编程大作业报告+MAT
- 基于MATLAB的波场模拟
- 遥感数字图像处理内含Matlab)代码
- 超像素分割matlab代码
- Matlab有限元分析与应用(电子书以及
- 最优化方法及其Matlab程序设计(可复
- Bursa_Wolf,布尔莎坐标转换matlab
- g.726 源代码 matlab
- MATLAB与机器学习
- 波束赋形——matlab程序
- 随机信号处理功率谱估计MATLAB程序及
- 支持向量机的matlab实现及相应Demo
- RGB 、YUV、YIQ 和 YCrCb颜色空间转换的
- 离散点云三维重建matlab程序
- 纹理图像分割Matlab源代码 PDF PPT
- libsvm - 支持多类别分类的svm工具箱m
- matlab实现三维点云三角化
- EMD HHT Matlab 信号分析,Google英文原版
- matlab GUI制作的播放器
- SIFT特征匹配 MATLAB 实现
评论
共有 条评论