annotate util/SMALL_showdict.m @ 203:f3b6ddd2f04f luisf_dev

checks if the variable SMALL_path exists, and exits otherwise.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 20 Mar 2012 15:52:22 +0000
parents 8e660fd14774
children
rev   line source
ivan@113 1 function x = SMALL_showdict(D,sz,n,m,varargin)
ivan@113 2 %% SMALL_SHOWDICT Display a dictionary of image patches.
ivan@128 3 % Reimplementation of showdict function from KSVD toolbox with Image
ivan@128 4 % Processing toolbox dependecies removed
ivan@113 5 %
ivan@113 6 % SMALL_SHOWDICT(D,SZ,N,M) displays the contents of the dictionary D, whos
ivan@113 7 % columns are 2-D image patches (in column-major order). SZ = [SX SY] is
ivan@113 8 % the size of the image patches. SHOWDICT displays the atoms on an N x M
ivan@113 9 % grid. If there are more atoms in D then only the first N*M are
ivan@113 10 % displayed.
ivan@113 11 %
ivan@113 12 % SMALL_SHOWDICT(...,'lines') separates the dictionary atoms by black lines.
ivan@113 13 % SMALL_SHOWDICT(...,'whitelines') separates the dictionary atoms by white
ivan@113 14 % lines.
ivan@113 15 %
ivan@113 16 % SMALL_SHOWDICT(...,'linewidth',W) when used with either 'lines' or
ivan@113 17 % 'whitelines' sets the width of the lines to W pixels (default=1).
ivan@113 18 %
ivan@113 19 % SMALL_SHOWDICT(...,'highcontrast') increases the contrast of the figure by
ivan@113 20 % normalizing the intensity values of each atom individually to the range
ivan@113 21 % of [0,1] (the default behavior is to normalize the values of the entire
ivan@113 22 % figure to [0,1] as one image). Note that in this way, the relative
ivan@113 23 % intensities of the atoms are not maintained.
ivan@113 24 %
ivan@113 25 % X = SMALL_SHOWDICT(...) returns a bitmat of the dictionary image without
ivan@113 26 % displaying the figure.
ivan@113 27
ivan@113 28 % Centre for Digital Music, Queen Mary, University of London.
ivan@113 29 % This file copyright 2011 Ivan Damnjanovic.
ivan@113 30 %
ivan@113 31 % This program is free software; you can redistribute it and/or
ivan@113 32 % modify it under the terms of the GNU General Public License as
ivan@113 33 % published by the Free Software Foundation; either version 2 of the
ivan@113 34 % License, or (at your option) any later version. See the file
ivan@113 35 % COPYING included with this distribution for more information.
ivan@113 36 %
ivan@113 37 %%
ivan@113 38
ivan@113 39 if (size(D,2) < n*m)
ivan@113 40 D = [D zeros(size(D,1),n*m-size(D,2))];
ivan@113 41 end
ivan@113 42
ivan@113 43
ivan@113 44 %%% parse input arguments %%%
ivan@113 45
ivan@113 46 linewidth = 1;
ivan@113 47 highcontrast = 0;
ivan@113 48 drawlines = 0;
ivan@113 49 linecolor = 0;
ivan@113 50
ivan@113 51 for i = 1:length(varargin)
ivan@113 52 if (~ischar(varargin{i}))
ivan@113 53 continue;
ivan@113 54 end
ivan@113 55 switch(varargin{i})
ivan@113 56 case 'highcontrast'
ivan@113 57 highcontrast = 1;
ivan@113 58 case 'lines'
ivan@113 59 drawlines = 1;
ivan@113 60 case 'whitelines'
ivan@113 61 drawlines = 1;
ivan@113 62 linecolor = 1;
ivan@113 63 case 'linewidth'
ivan@113 64 linewidth = varargin{i+1};
ivan@113 65 end
ivan@113 66 end
ivan@113 67
ivan@113 68
ivan@113 69
ivan@113 70 %%% create dictionary image %%%
ivan@113 71
ivan@113 72
ivan@113 73 if (drawlines)
ivan@113 74
ivan@113 75 D = [D ; nan(sz(1)*linewidth,size(D,2))];
ivan@113 76 sz(2) = sz(2)+linewidth;
ivan@113 77 x = col2imstep(D(:,1:n*m),[n m].*sz, sz, sz);
ivan@113 78 sz = [sz(2) sz(1)];
ivan@113 79 D = im2colstep(x',sz, sz);
ivan@113 80 D = [D ; nan(sz(1)*linewidth,size(D,2))];
ivan@113 81 sz(2) = sz(2)+linewidth;
ivan@113 82 x = col2imstep(D(:,1:n*m),[m n].*sz,sz,sz);
ivan@113 83 x = x';
ivan@113 84 x = x(1:end-linewidth,1:end-linewidth);
ivan@113 85
ivan@113 86 if (highcontrast)
ivan@113 87 for i = 0:n-1
ivan@113 88 for j = 0:m-1
ivan@113 89 x(i*sz(1)+1:i*sz(1)+sz(1)-linewidth, j*sz(2)+1:j*sz(2)+sz(2)-linewidth) = ...
ivan@113 90 imnormalize(x(i*sz(1)+1:i*sz(1)+sz(1)-linewidth, j*sz(2)+1:j*sz(2)+sz(2)-linewidth));
ivan@113 91 end
ivan@113 92 end
ivan@113 93 else
ivan@113 94 x = imnormalize(x);
ivan@113 95 end
ivan@113 96
ivan@113 97 x(isnan(x)) = linecolor;
ivan@113 98
ivan@113 99 else
ivan@113 100
ivan@113 101 x = col2imstep(D(:,1:n*m),[n m].*sz, sz, sz);
ivan@113 102
ivan@113 103 if (highcontrast)
ivan@113 104 for i = 0:n-1
ivan@113 105 for j = 0:m-1
ivan@113 106 x(i*sz(1)+1:i*sz(1)+sz(1), j*sz(2)+1:j*sz(2)+sz(2)) = ...
ivan@113 107 imnormalize(x(i*sz(1)+1:i*sz(1)+sz(1), j*sz(2)+1:j*sz(2)+sz(2)));
ivan@113 108 end
ivan@113 109 end
ivan@113 110 else
ivan@113 111 x = imnormalize(x);
ivan@113 112 end
ivan@113 113 end
ivan@113 114
ivan@113 115
ivan@113 116 if (nargout==0)
ivan@113 117 imagesc(dictimg);colormap(gray);axis off; axis image;
ivan@113 118 end