summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmWrite.m
diff options
context:
space:
mode:
authorleochanj105 <leochanj@live.unc.edu>2020-10-20 03:47:33 -0400
committerleochanj105 <leochanj@live.unc.edu>2020-10-20 03:47:33 -0400
commita32f220f06cc463e5b56e7fa0b1b1334d94d08f3 (patch)
tree4af4caa60074465d85fc2ef5cc1b23e74c064329 /SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmWrite.m
parent79f30887129145e15e5172e36a7d7602859fc932 (diff)
matlab removed
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmWrite.m')
-rwxr-xr-xSD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmWrite.m120
1 files changed, 0 insertions, 120 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmWrite.m b/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmWrite.m
deleted file mode 100755
index 09c14c9..0000000
--- a/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/pgmWrite.m
+++ /dev/null
@@ -1,120 +0,0 @@
1% RANGE = pgmWrite(MTX, FILENAME, RANGE, TYPE, COMMENT)
2%
3% Write a MatLab matrix to a pgm (graylevel image) file.
4% This format is accessible from the XV image browsing utility.
5%
6% RANGE (optional) is a 2-vector specifying the values that map to
7% black and white, respectively. Passing a value of 'auto' (default)
8% sets RANGE=[min,max] (as in MatLab's imagesc). 'auto2' sets
9% RANGE=[mean-2*stdev, mean+2*stdev]. 'auto3' sets
10% RANGE=[p1-(p2-p1)/8, p2+(p2-p1)/8], where p1 is the 10th percentile
11% value of the sorted MATRIX samples, and p2 is the 90th percentile
12% value.
13%
14% TYPE (optional) should be 'raw' or 'ascii'. Defaults to 'raw'.
15
16% Hany Farid, Spring '96. Modified by Eero Simoncelli, 6/96.
17
18function range = pgmWrite(mtx, fname, range, type, comment );
19
20[fid,msg] = fopen( fname, 'w' );
21
22if (fid == -1)
23 error(msg);
24end
25
26%------------------------------------------------------------
27%% optional ARGS:
28
29if (exist('range') ~= 1)
30 range = 'auto';
31end
32
33if (exist('type') ~= 1)
34 type = 'raw';
35end
36%------------------------------------------------------------
37
38%% Automatic range calculation:
39if (strcmp(range,'auto1') | strcmp(range,'auto'))
40 [mn,mx] = range2(mtx);
41 range = [mn,mx];
42
43elseif strcmp(range,'auto2')
44 stdev = sqrt(var2(mtx));
45 av = mean2(mtx);
46 range = [av-2*stdev,av+2*stdev]; % MAGIC NUMBER: 2 stdevs
47
48elseif strcmp(range, 'auto3')
49 percentile = 0.1; % MAGIC NUMBER: 0<p<0.5
50 [N,X] = histo(mtx);
51 binsz = X(2)-X(1);
52 N = N+1e-10; % Ensure cumsum will be monotonic for call to interp1
53 cumN = [0, cumsum(N)]/sum(N);
54 cumX = [X(1)-binsz, X] + (binsz/2);
55 ctrRange = interp1(cumN,cumX, [percentile, 1-percentile]);
56 range = mean(ctrRange) + (ctrRange-mean(ctrRange))/(1-2*percentile);
57
58elseif isstr(range)
59 error(sprintf('Bad RANGE argument: %s',range))
60
61end
62
63if ((range(2) - range(1)) <= eps)
64 range(1) = range(1) - 0.5;
65 range(2) = range(2) + 0.5;
66end
67
68
69%%% First line contains ID string:
70%%% "P1" = ascii bitmap, "P2" = ascii greymap,
71%%% "P3" = ascii pixmap, "P4" = raw bitmap,
72%%% "P5" = raw greymap, "P6" = raw pixmap
73if strcmp(type,'raw')
74 fprintf(fid,'P5\n');
75 format = 5;
76elseif strcmp(type,'ascii')
77 fprintf(fid,'P2\n');
78 format = 2;
79else
80 error(sprintf('PGMWRITE: Bad type argument: %s',type));
81end
82
83fprintf(fid,'# MatLab PGMWRITE file, saved %s\n',date);
84
85if (exist('comment') == 1)
86 fprintf(fid,'# %s\n', comment);
87end
88
89%%% dimensions
90fprintf(fid,'%d %d\n',size(mtx,2),size(mtx,1));
91
92%%% Maximum pixel value
93fprintf(fid,'255\n');
94
95
96%% MatLab's "fprintf" floors when writing floats, so we compute
97%% (mtx-r1)*255/(r2-r1)+0.5
98mult = (255 / (range(2)-range(1)));
99mtx = (mult * mtx) + (0.5 - mult * range(1));
100
101mtx = max(-0.5+eps,min(255.5-eps,mtx));
102
103if (format == 2)
104 count = fprintf(fid,'%d ',mtx');
105elseif (format == 5)
106 count = fwrite(fid,mtx','uchar');
107end
108
109fclose(fid);
110
111if (count ~= size(mtx,1)*size(mtx,2))
112 fprintf(1,'Warning: File output terminated early!');
113end
114
115%%% TEST:
116% foo = 257*rand(100)-1;
117% pgmWrite(foo,'foo.pgm',[0 255]);
118% foo2=pgmRead('foo.pgm');
119% size(find((foo2-round(foo))~=0))
120% foo(find((foo2-round(foo))~=0))