writepgm.m

来自「人脸识别matlab程序 with a principal component」· M 代码 · 共 37 行

M
37
字号
function writepgm(image,filename)%WRITEPGM Write a matrix as a raw pgm file%         WRITEPGM(IMAGE,FILENAME) writes the array image as a raw PGM%         file to FILENAME.%% Matthew Dailey 1999if ~(image <= 255 & image >= 0)  error('Image pixels out of range.');end;% Open the file%fprintf(1,'Opening %s...\n',filename);fid = fopen(filename,'w');if fid <= 0  error(sprintf('Could not open %s for writing.',filename));end;width = size(image,2);height = size(image,1);% Write header informationfprintf(fid,'P5\n');fprintf(fid,'%d %d\n',width,height);fprintf(fid,'255\n');% Write the raw data -- transpose first thoughcount = fwrite(fid,image','uchar');if count ~= width*height  error(sprintf('Could not write all data to %s', outfile));end;fclose(fid);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?