From f618466c25d43f3bae9e40920273bf77de1e1149 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Mon, 19 Oct 2020 23:09:30 -0400 Subject: initial sd-vbs initial sd-vbs add sd-vbs sd-vbs --- .../texture_synthesis/src/matlabPyrTools/pgmRead.m | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmRead.m (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmRead.m') diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmRead.m b/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmRead.m new file mode 100755 index 0000000..86c3b62 --- /dev/null +++ b/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmRead.m @@ -0,0 +1,59 @@ +% IM = pgmRead( FILENAME ) +% +% Load a pgm image into a MatLab matrix. +% This format is accessible from the XV image browsing utility. +% Only works for 8bit gray images (raw or ascii) + +% Hany Farid, Spring '96. Modified by Eero Simoncelli, 6/96. + +function im = pgmRead( fname ); + +[fid,msg] = fopen( fname, 'r' ); + +if (fid == -1) + error(msg); +end + +%%% First line contains ID string: +%%% "P1" = ascii bitmap, "P2" = ascii greymap, +%%% "P3" = ascii pixmap, "P4" = raw bitmap, +%%% "P5" = raw greymap, "P6" = raw pixmap +TheLine = fgetl(fid); +format = TheLine; + +if ~((format(1:2) == 'P2') | (format(1:2) == 'P5')) + error('PGM file must be of type P2 or P5'); +end + +%%% Any number of comment lines +TheLine = fgetl(fid); +while TheLine(1) == '#' + TheLine = fgetl(fid); +end + +%%% dimensions +sz = sscanf(TheLine,'%d',2); +xdim = sz(1); +ydim = sz(2); +sz = xdim * ydim; + +%%% Maximum pixel value +TheLine = fgetl(fid); +maxval = sscanf(TheLine, '%d',1); + +%%im = zeros(dim,1); +if (format(2) == '2') + [im,count] = fscanf(fid,'%d',sz); +else + [im,count] = fread(fid,sz,'uchar'); +end + +fclose(fid); + +if (count == sz) + im = reshape( im, xdim, ydim )'; +else + fprintf(1,'Warning: File ended early!'); + im = reshape( [im ; zeros(sz-count,1)], xdim, ydim)'; +end + -- cgit v1.2.2