diff options
| author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
|---|---|---|
| committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
| commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
| tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m | |
| parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (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-x | SD-VBS/benchmarks/texture_synthesis/src/matlab/pgmRead.m | 59 |
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 | |||
| 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 | |||
