matlab中读取PPM格式的图像程序.docx

上传人:牧羊曲112 文档编号:3161188 上传时间:2023-03-11 格式:DOCX 页数:2 大小:36.55KB
返回 下载 相关 举报
matlab中读取PPM格式的图像程序.docx_第1页
第1页 / 共2页
matlab中读取PPM格式的图像程序.docx_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《matlab中读取PPM格式的图像程序.docx》由会员分享,可在线阅读,更多相关《matlab中读取PPM格式的图像程序.docx(2页珍藏版)》请在三一办公上搜索。

1、matlab中读取PPM格式的图像程序function I,w,h,level = ppmread(path) %* % Title: Ppmread % Input Parameter: path of the ppm file % Description: This file reads .ppm file % open the file in read mode f= fopen(path,r); A = 0 ; % Ascii flag % ignore the comments in the file a = fscanf(f,%s,1); while(a(1)=#) a = fsc

2、anf(f,%s,1); end % check magic number if (strcmp(a,P3)=0) &(strcmp(a,P6)=0) while(a(1)=#) a = fscanf(f,%s,1); end display(its not ppm file); else display(its ppm file); if(strcmp(a,P3) A = 1; end a = fscanf(f,%s,1); while(a(1) = #) b = fgets(f); % throw away the comments line a= fscanf(f,%s,1); % re

3、ad first character of next line end w = str2num(a); % width of image a= fscanf(f,%s,1); while(a(1) = #) b = fgets(f); a= fscanf(f,%s,1); end h = str2num(a); % hight of image a= fscanf(f,%s,1); while(a(1) = #) b = fgets(f); % throw away the comments line a= fscanf(f,%s,1); end level = str2num(a); % c

4、olour levels if (A = 1) for i = 1:h for j = 1:w I(i,j,1) = fscanf(f,%i,1); % Red I(i,j,2) = fscanf(f,%i,1); % Green I(i,j,3) = fscanf(f,%i,1); % Blue end end else % Skip one more char fread(f,1); % Now read the matrix Arr = uint8(fread(f); index = 0; for i = 1:1:h for j = 1:w index = index+1; I(i,j,1) = Arr(index); index = index+1; I(i,j,2) = Arr(index); index = index+1; I(i,j,3) = Arr(index); end end end end

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号