summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m
blob: 6ad818a316ce32899d3613b1779a586b94d32c59 (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
31
32
33
34
35
36
37
38
39
40
41
42
function [img,sizeinfo] = 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.


fname_header = sprintf('%s.h01',filename);
fname_data = sprintf('%s.i01',filename);

fid = fopen(fname_header,'r');


done = 0;
while done~=3,
  cmt = fgets(fid)
  if (findstr(cmt,'!matrix size[1]')),
    nc = sscanf(cmt,'!matrix size[1] :=%d');
    done = done+1;
  elseif (findstr(cmt,'!matrix size[2]')),
    nr = sscanf(cmt,'!matrix size[2] :=%d');
    done = done+1;
  elseif (findstr(cmt,'!matrix size[3]')),
    ns = sscanf(cmt,'!matrix size[3] :=%d');
    done = done+1;
  end
end
fclose(fid);

fid = fopen(fname_data,'r');

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

img = fread(fid,nc*nr*ns,'uint8');
img = reshape(img,nc,nr,ns);

sizeinfo(1) = nr;
sizeinfo(2) = nc;
sizeinfo(3) = ns;

fclose(fid);