summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m')
-rwxr-xr-xSD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m59
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
9function im = pgmRead( fname );
10
11[fid,msg] = fopen( fname, 'r' );
12
13if (fid == -1)
14 error(msg);
15end
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
21TheLine = fgetl(fid);
22format = TheLine;
23
24if ~((format(1:2) == 'P2') | (format(1:2) == 'P5'))
25 error('PGM file must be of type P2 or P5');
26end
27
28%%% Any number of comment lines
29TheLine = fgetl(fid);
30while TheLine(1) == '#'
31 TheLine = fgetl(fid);
32end
33
34%%% dimensions
35sz = sscanf(TheLine,'%d',2);
36xdim = sz(1);
37ydim = sz(2);
38sz = xdim * ydim;
39
40%%% Maximum pixel value
41TheLine = fgetl(fid);
42maxval = sscanf(TheLine, '%d',1);
43
44%%im = zeros(dim,1);
45if (format(2) == '2')
46 [im,count] = fscanf(fid,'%d',sz);
47else
48 [im,count] = fread(fid,sz,'uchar');
49end
50
51fclose(fid);
52
53if (count == sz)
54 im = reshape( im, xdim, ydim )';
55else
56 fprintf(1,'Warning: File ended early!');
57 im = reshape( [im ; zeros(sz-count,1)], xdim, ydim)';
58end
59