diff options
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m')
-rwxr-xr-x | SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m b/SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m deleted file mode 100755 index 86c3b62..0000000 --- a/SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | % IM = pgmRead( FILENAME ) | ||
2 | % | ||
3 | % Load a pgm image into a MatLab matrix. | ||
4 | % This format is accessible from the XV image browsing utility. | ||
5 | % Only works for 8bit gray images (raw or ascii) | ||
6 | |||
7 | % Hany Farid, Spring '96. Modified by Eero Simoncelli, 6/96. | ||
8 | |||
9 | function im = pgmRead( fname ); | ||
10 | |||
11 | [fid,msg] = fopen( fname, 'r' ); | ||
12 | |||
13 | if (fid == -1) | ||
14 | error(msg); | ||
15 | end | ||
16 | |||
17 | %%% First line contains ID string: | ||
18 | %%% "P1" = ascii bitmap, "P2" = ascii greymap, | ||
19 | %%% "P3" = ascii pixmap, "P4" = raw bitmap, | ||
20 | %%% "P5" = raw greymap, "P6" = raw pixmap | ||
21 | TheLine = fgetl(fid); | ||
22 | format = TheLine; | ||
23 | |||
24 | if ~((format(1:2) == 'P2') | (format(1:2) == 'P5')) | ||
25 | error('PGM file must be of type P2 or P5'); | ||
26 | end | ||
27 | |||
28 | %%% Any number of comment lines | ||
29 | TheLine = fgetl(fid); | ||
30 | while TheLine(1) == '#' | ||
31 | TheLine = fgetl(fid); | ||
32 | end | ||
33 | |||
34 | %%% dimensions | ||
35 | sz = sscanf(TheLine,'%d',2); | ||
36 | xdim = sz(1); | ||
37 | ydim = sz(2); | ||
38 | sz = xdim * ydim; | ||
39 | |||
40 | %%% Maximum pixel value | ||
41 | TheLine = fgetl(fid); | ||
42 | maxval = sscanf(TheLine, '%d',1); | ||
43 | |||
44 | %%im = zeros(dim,1); | ||
45 | if (format(2) == '2') | ||
46 | [im,count] = fscanf(fid,'%d',sz); | ||
47 | else | ||
48 | [im,count] = fread(fid,sz,'uchar'); | ||
49 | end | ||
50 | |||
51 | fclose(fid); | ||
52 | |||
53 | if (count == sz) | ||
54 | im = reshape( im, xdim, ydim )'; | ||
55 | else | ||
56 | fprintf(1,'Warning: File ended early!'); | ||
57 | im = reshape( [im ; zeros(sz-count,1)], xdim, ydim)'; | ||
58 | end | ||
59 | |||