summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m
diff options
context:
space:
mode:
authorleochanj105 <leochanj@live.unc.edu>2020-10-19 23:09:30 -0400
committerleochanj105 <leochanj@live.unc.edu>2020-10-20 02:40:39 -0400
commitf618466c25d43f3bae9e40920273bf77de1e1149 (patch)
tree460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m
parent47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff)
initial sd-vbs
initial sd-vbs add sd-vbs sd-vbs
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, 59 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m b/SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m
new file mode 100755
index 0000000..86c3b62
--- /dev/null
+++ b/SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m
@@ -0,0 +1,59 @@
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