diff options
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/showIm.m')
| -rwxr-xr-x | SD-VBS/benchmarks/texture_synthesis/src/matlab/showIm.m | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/showIm.m b/SD-VBS/benchmarks/texture_synthesis/src/matlab/showIm.m deleted file mode 100755 index a9e2bd1..0000000 --- a/SD-VBS/benchmarks/texture_synthesis/src/matlab/showIm.m +++ /dev/null | |||
| @@ -1,221 +0,0 @@ | |||
| 1 | % RANGE = showIm (MATRIX, RANGE, ZOOM, LABEL, NSHADES ) | ||
| 2 | % | ||
| 3 | % Display a MatLab MATRIX as a grayscale image in the current figure, | ||
| 4 | % inside the current axes. If MATRIX is complex, the real and imaginary | ||
| 5 | % parts are shown side-by-side, with the same grayscale mapping. | ||
| 6 | % | ||
| 7 | % If MATRIX is a string, it should be the name of a variable bound to a | ||
| 8 | % MATRIX in the base (global) environment. This matrix is displayed as an | ||
| 9 | % image, with the title set to the string. | ||
| 10 | % | ||
| 11 | % RANGE (optional) is a 2-vector specifying the values that map to | ||
| 12 | % black and white, respectively. Passing a value of 'auto' (default) | ||
| 13 | % sets RANGE=[min,max] (as in MatLab's imagesc). 'auto2' sets | ||
| 14 | % RANGE=[mean-2*stdev, mean+2*stdev]. 'auto3' sets | ||
| 15 | % RANGE=[p1-(p2-p1)/8, p2+(p2-p1)/8], where p1 is the 10th percentile | ||
| 16 | % value of the sorted MATRIX samples, and p2 is the 90th percentile | ||
| 17 | % value. | ||
| 18 | % | ||
| 19 | % ZOOM specifies the number of matrix samples per screen pixel. It | ||
| 20 | % will be rounded to an integer, or 1 divided by an integer. A value | ||
| 21 | % of 'same' or 'auto' (default) causes the zoom value to be chosen | ||
| 22 | % automatically to fit the image into the current axes. A value of | ||
| 23 | % 'full' fills the axis region (leaving no room for labels). See | ||
| 24 | % pixelAxes.m. | ||
| 25 | % | ||
| 26 | % If LABEL (optional, default = 1, unless zoom='full') is non-zero, the range | ||
| 27 | % of values that are mapped into the gray colormap and the dimensions | ||
| 28 | % (size) of the matrix and zoom factor are printed below the image. If label | ||
| 29 | % is a string, it is used as a title. | ||
| 30 | % | ||
| 31 | % NSHADES (optional) specifies the number of gray shades, and defaults | ||
| 32 | % to the size of the current colormap. | ||
| 33 | |||
| 34 | % Eero Simoncelli, 6/96. | ||
| 35 | |||
| 36 | %%TODO: should use "newplot" | ||
| 37 | |||
| 38 | function range = showIm( im, range, zoom, label, nshades ); | ||
| 39 | |||
| 40 | %------------------------------------------------------------ | ||
| 41 | %% OPTIONAL ARGS: | ||
| 42 | |||
| 43 | if (nargin < 1) | ||
| 44 | error('Requires at least one input argument.'); | ||
| 45 | end | ||
| 46 | |||
| 47 | MLv = version; | ||
| 48 | |||
| 49 | if isstr(im) | ||
| 50 | if (strcmp(MLv(1),'4')) | ||
| 51 | error('Cannot pass string arg for MATRIX in MatLab version 4.x'); | ||
| 52 | end | ||
| 53 | label = im; | ||
| 54 | im = evalin('base',im); | ||
| 55 | end | ||
| 56 | |||
| 57 | if (exist('range') ~= 1) | ||
| 58 | range = 'auto1'; | ||
| 59 | end | ||
| 60 | |||
| 61 | if (exist('nshades') ~= 1) | ||
| 62 | nshades = size(colormap,1); | ||
| 63 | end | ||
| 64 | nshades = max( nshades, 2 ); | ||
| 65 | |||
| 66 | if (exist('zoom') ~= 1) | ||
| 67 | zoom = 'auto'; | ||
| 68 | end | ||
| 69 | |||
| 70 | if (exist('label') ~= 1) | ||
| 71 | if strcmp(zoom,'full') | ||
| 72 | label = 0; % no labeling | ||
| 73 | else | ||
| 74 | label = 1; % just print grayrange & dims | ||
| 75 | end | ||
| 76 | end | ||
| 77 | |||
| 78 | %------------------------------------------------------------ | ||
| 79 | |||
| 80 | %% Automatic range calculation: | ||
| 81 | if (strcmp(range,'auto1') | strcmp(range,'auto')) | ||
| 82 | if isreal(im) | ||
| 83 | [mn,mx] = range2(im); | ||
| 84 | else | ||
| 85 | [mn1,mx1] = range2(real(im)); | ||
| 86 | [mn2,mx2] = range2(imag(im)); | ||
| 87 | mn = min(mn1,mn2); | ||
| 88 | mx = max(mx1,mx2); | ||
| 89 | end | ||
| 90 | if any(size(im)==1) | ||
| 91 | pad = (mx-mn)/12; % MAGIC NUMBER: graph padding | ||
| 92 | range = [mn-pad, mx+pad]; | ||
| 93 | else | ||
| 94 | range = [mn,mx]; | ||
| 95 | end | ||
| 96 | |||
| 97 | elseif strcmp(range,'auto2') | ||
| 98 | if isreal(im) | ||
| 99 | stdev = sqrt(var2(im)); | ||
| 100 | av = mean2(im); | ||
| 101 | else | ||
| 102 | stdev = sqrt((var2(real(im)) + var2(imag(im)))/2); | ||
| 103 | av = (mean2(real(im)) + mean2(imag(im)))/2; | ||
| 104 | end | ||
| 105 | range = [av-2*stdev,av+2*stdev]; % MAGIC NUMBER: 2 stdevs | ||
| 106 | |||
| 107 | elseif strcmp(range, 'auto3') | ||
| 108 | percentile = 0.1; % MAGIC NUMBER: 0<p<0.5 | ||
| 109 | [N,X] = histo(im); | ||
| 110 | binsz = X(2)-X(1); | ||
| 111 | N = N+1e-10; % Ensure cumsum will be monotonic for call to interp1 | ||
| 112 | cumN = [0, cumsum(N)]/sum(N); | ||
| 113 | cumX = [X(1)-binsz, X] + (binsz/2); | ||
| 114 | ctrRange = interp1(cumN,cumX, [percentile, 1-percentile]); | ||
| 115 | range = mean(ctrRange) + (ctrRange-mean(ctrRange))/(1-2*percentile); | ||
| 116 | |||
| 117 | elseif isstr(range) | ||
| 118 | error(sprintf('Bad RANGE argument: %s',range)) | ||
| 119 | |||
| 120 | end | ||
| 121 | |||
| 122 | if ((range(2) - range(1)) <= eps) | ||
| 123 | range(1) = range(1) - 0.5; | ||
| 124 | range(2) = range(2) + 0.5; | ||
| 125 | end | ||
| 126 | |||
| 127 | |||
| 128 | if isreal(im) | ||
| 129 | factor=1; | ||
| 130 | else | ||
| 131 | factor = 1+sqrt(-1); | ||
| 132 | end | ||
| 133 | |||
| 134 | xlbl_offset = 0; % default value | ||
| 135 | |||
| 136 | if (~any(size(im)==1)) | ||
| 137 | %% MatLab's "image" rounds when mapping to the colormap, so we compute | ||
| 138 | %% (im-r1)*(nshades-1)/(r2-r1) + 1.5 | ||
| 139 | mult = ((nshades-1) / (range(2)-range(1))); | ||
| 140 | d_im = (mult * im) + factor*(1.5 - range(1)*mult); | ||
| 141 | end | ||
| 142 | |||
| 143 | if isreal(im) | ||
| 144 | if (any(size(im)==1)) | ||
| 145 | hh = plot( im); | ||
| 146 | axis([1, prod(size(im)), range]); | ||
| 147 | else | ||
| 148 | hh = image( d_im ); | ||
| 149 | axis('off'); | ||
| 150 | zoom = pixelAxes(size(d_im),zoom); | ||
| 151 | end | ||
| 152 | else | ||
| 153 | if (any(size(im)==1)) | ||
| 154 | subplot(2,1,1); | ||
| 155 | hh = plot(real(im)); | ||
| 156 | axis([1, prod(size(im)), range]); | ||
| 157 | subplot(2,1,2); | ||
| 158 | hh = plot(imag(im)); | ||
| 159 | axis([1, prod(size(im)), range]); | ||
| 160 | else | ||
| 161 | subplot(1,2,1); | ||
| 162 | hh = image(real(d_im)); | ||
| 163 | axis('off'); zoom = pixelAxes(size(d_im),zoom); | ||
| 164 | ax = gca; orig_units = get(ax,'Units'); | ||
| 165 | set(ax,'Units','points'); | ||
| 166 | pos1 = get(ax,'Position'); | ||
| 167 | set(ax,'Units',orig_units); | ||
| 168 | subplot(1,2,2); | ||
| 169 | hh = image(imag(d_im)); | ||
| 170 | axis('off'); zoom = pixelAxes(size(d_im),zoom); | ||
| 171 | ax = gca; orig_units = get(ax,'Units'); | ||
| 172 | set(ax,'Units','points'); | ||
| 173 | pos2 = get(ax,'Position'); | ||
| 174 | set(ax,'Units',orig_units); | ||
| 175 | xlbl_offset = (pos1(1)-pos2(1))/2; | ||
| 176 | end | ||
| 177 | end | ||
| 178 | |||
| 179 | if ~any(size(im)==1) | ||
| 180 | colormap(gray(nshades)); | ||
| 181 | end | ||
| 182 | |||
| 183 | if ((label ~= 0)) | ||
| 184 | if isstr(label) | ||
| 185 | title(label); | ||
| 186 | h = get(gca,'Title'); | ||
| 187 | orig_units = get(h,'Units'); | ||
| 188 | set(h,'Units','points'); | ||
| 189 | pos = get(h,'Position'); | ||
| 190 | pos(1:2) = pos(1:2) + [xlbl_offset, | ||
