annotate util/SMALL_showdict.m @ 113:028599837f1d sup_158_IMG_Processing_toolbox_

Reimplementation of showdict.m function from KSVD toolbox - Image Processing toolbox independent.
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Tue, 24 May 2011 15:13:41 +0100
parents
children 8e660fd14774
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@113 3 %% Reimplementation of showdict function from KSVD toolbox with Image
ivan@113 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
ivan@113 29 % Centre for Digital Music, Queen Mary, University of London.
ivan@113 30 % This file copyright 2011 Ivan Damnjanovic.
ivan@113 31 %
ivan@113 32 % This program is free software; you can redistribute it and/or
ivan@113 33 % modify it under the terms of the GNU General Public License as
ivan@113 34 % published by the Free Software Foundation; either version 2 of the
ivan@113 35 % License, or (at your option) any later version. See the file
ivan@113 36 % COPYING included with this distribution for more information.
ivan@113 37 %
ivan@113 38 %%
ivan@113 39
ivan@113 40 if (size(D,2) < n*m)
ivan@113 41 D = [D zeros(size(D,1),n*m-size(D,2))];
ivan@113 42 end
ivan@113 43
ivan@113 44
ivan@113 45 %%% parse input arguments %%%
ivan@113 46
ivan@113 47 linewidth = 1;
ivan@113 48 highcontrast = 0;
ivan@113 49 drawlines = 0;
ivan@113 50 linecolor = 0;
ivan@113 51
ivan@113 52 for i = 1:length(varargin)
ivan@113 53 if (~ischar(varargin{i}))
ivan@113 54 continue;
ivan@113 55 end
ivan@113 56 switch(varargin{i})
ivan@113 57 case 'highcontrast'
ivan@113 58 highcontrast = 1;
ivan@113 59 case 'lines'
ivan@113 60 drawlines = 1;
ivan@113 61 case 'whitelines'
ivan@113 62 drawlines = 1;
ivan@113 63 linecolor = 1;
ivan@113 64 case 'linewidth'
ivan@113 65 linewidth = varargin{i+1};
ivan@113 66 end
ivan@113 67 end
ivan@113 68
ivan@113 69
ivan@113 70
ivan@113 71 %%% create dictionary image %%%
ivan@113 72
ivan@113 73
ivan@113 74 if (drawlines)
ivan@113 75
ivan@113 76 D = [D ; nan(sz(1)*linewidth,size(D,2))];
ivan@113 77 sz(2) = sz(2)+linewidth;
ivan@113 78 x = col2imstep(D(:,1:n*m),[n m].*sz, sz, sz);
ivan@113 79 sz = [sz(2) sz(1)];
ivan@113 80 D = im2colstep(x',sz, sz);
ivan@113 81 D = [D ; nan(sz(1)*linewidth,size(D,2))];
ivan@113 82 sz(2) = sz(2)+linewidth;
ivan@113 83 x = col2imstep(D(:,1:n*m),[m n].*sz,sz,sz);
ivan@113 84 x = x';
ivan@113 85 x = x(1:end-linewidth,1:end-linewidth);
ivan@113 86
ivan@113 87 if (highcontrast)
ivan@113 88 for i = 0:n-1
ivan@113 89 for j = 0:m-1
ivan@113 90 x(i*sz(1)+1:i*sz(1)+sz(1)-linewidth, j*sz(2)+1:j*sz(2)+sz(2)-linewidth) = ...
ivan@113 91 imnormalize(x(i*sz(1)+1:i*sz(1)+sz(1)-linewidth, j*sz(2)+1:j*sz(2)+sz(2)-linewidth));
ivan@113 92 end
ivan@113 93 end
ivan@113 94 else
ivan@113 95 x = imnormalize(x);
ivan@113 96 end
ivan@113 97
ivan@113 98 x(isnan(x)) = linecolor;
ivan@113 99
ivan@113 100 else
ivan@113 101
ivan@113 102 x = col2imstep(D(:,1:n*m),[n m].*sz, sz, sz);
ivan@113 103
ivan@113 104 if (highcontrast)
ivan@113 105 for i = 0:n-1
ivan@113 106 for j = 0:m-1
ivan@113 107 x(i*sz(1)+1:i*sz(1)+sz(1), j*sz(2)+1:j*sz(2)+sz(2)) = ...
ivan@113 108 imnormalize(x(i*sz(1)+1:i*sz(1)+sz(1), j*sz(2)+1:j*sz(2)+sz(2)));
ivan@113 109 end
ivan@113 110 end
ivan@113 111 else
ivan@113 112 x = imnormalize(x);
ivan@113 113 end
ivan@113 114 end
ivan@113 115
ivan@113 116
ivan@113 117 if (nargout==0)
ivan@113 118 imagesc(dictimg);colormap(gray);axis off; axis image;
ivan@113 119 end