forked from corehello/RPCA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwritepgm.m
28 lines (28 loc) · 804 Bytes
/
writepgm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 1999
[m,n] = size(image);
% if ~((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 information
fprintf(fid,'P5\n');
fprintf(fid,'%d %d\n',width,height);
fprintf(fid,'255\n');
% Write the raw data -- transpose first though
count = fwrite(fid,image','uchar');
if count ~= width*height
error(sprintf('Could not write all data to %s', outfile));
end;
fclose(fid);