summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m
blob: 7aaf998e91d417a2c67539a022dcb6c02be3de6f (plain) (blame)
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
29
30
function img = pgmread(filename)
% function img = pgmread(filename)
%   this is my version of pgmread for the pgm file created by XV.
%   
%  this program also corrects for the shifts in the image from pm file.


fid = fopen(filename,'r');
if (fid < 0),
   error(sprintf('can not find file: %s',filename));
end

fscanf(fid, 'P5\n');
cmt = '#';
while findstr(cmt, '#'),
  cmt = fgets(fid);
   if length(findstr(cmt, '#')) ~= 1,
      YX = sscanf(cmt, '%d %d');
      y = YX(1); x = YX(2);
   end
end

fgets(fid);

%img = fscanf(fid,'%d',size);
%img = img';

img = fread(fid,[y,x],'uint8');
img = img';
fclose(fid);