ivan@113: function x = SMALL_showdict(D,sz,n,m,varargin) ivan@113: %% SMALL_SHOWDICT Display a dictionary of image patches. ivan@128: % Reimplementation of showdict function from KSVD toolbox with Image ivan@128: % Processing toolbox dependecies removed ivan@113: % ivan@113: % SMALL_SHOWDICT(D,SZ,N,M) displays the contents of the dictionary D, whos ivan@113: % columns are 2-D image patches (in column-major order). SZ = [SX SY] is ivan@113: % the size of the image patches. SHOWDICT displays the atoms on an N x M ivan@113: % grid. If there are more atoms in D then only the first N*M are ivan@113: % displayed. ivan@113: % ivan@113: % SMALL_SHOWDICT(...,'lines') separates the dictionary atoms by black lines. ivan@113: % SMALL_SHOWDICT(...,'whitelines') separates the dictionary atoms by white ivan@113: % lines. ivan@113: % ivan@113: % SMALL_SHOWDICT(...,'linewidth',W) when used with either 'lines' or ivan@113: % 'whitelines' sets the width of the lines to W pixels (default=1). ivan@113: % ivan@113: % SMALL_SHOWDICT(...,'highcontrast') increases the contrast of the figure by ivan@113: % normalizing the intensity values of each atom individually to the range ivan@113: % of [0,1] (the default behavior is to normalize the values of the entire ivan@113: % figure to [0,1] as one image). Note that in this way, the relative ivan@113: % intensities of the atoms are not maintained. ivan@113: % ivan@113: % X = SMALL_SHOWDICT(...) returns a bitmat of the dictionary image without ivan@113: % displaying the figure. ivan@113: ivan@113: % Centre for Digital Music, Queen Mary, University of London. ivan@113: % This file copyright 2011 Ivan Damnjanovic. ivan@113: % ivan@113: % This program is free software; you can redistribute it and/or ivan@113: % modify it under the terms of the GNU General Public License as ivan@113: % published by the Free Software Foundation; either version 2 of the ivan@113: % License, or (at your option) any later version. See the file ivan@113: % COPYING included with this distribution for more information. ivan@113: % ivan@113: %% ivan@113: ivan@113: if (size(D,2) < n*m) ivan@113: D = [D zeros(size(D,1),n*m-size(D,2))]; ivan@113: end ivan@113: ivan@113: ivan@113: %%% parse input arguments %%% ivan@113: ivan@113: linewidth = 1; ivan@113: highcontrast = 0; ivan@113: drawlines = 0; ivan@113: linecolor = 0; ivan@113: ivan@113: for i = 1:length(varargin) ivan@113: if (~ischar(varargin{i})) ivan@113: continue; ivan@113: end ivan@113: switch(varargin{i}) ivan@113: case 'highcontrast' ivan@113: highcontrast = 1; ivan@113: case 'lines' ivan@113: drawlines = 1; ivan@113: case 'whitelines' ivan@113: drawlines = 1; ivan@113: linecolor = 1; ivan@113: case 'linewidth' ivan@113: linewidth = varargin{i+1}; ivan@113: end ivan@113: end ivan@113: ivan@113: ivan@113: ivan@113: %%% create dictionary image %%% ivan@113: ivan@113: ivan@113: if (drawlines) ivan@113: ivan@113: D = [D ; nan(sz(1)*linewidth,size(D,2))]; ivan@113: sz(2) = sz(2)+linewidth; ivan@113: x = col2imstep(D(:,1:n*m),[n m].*sz, sz, sz); ivan@113: sz = [sz(2) sz(1)]; ivan@113: D = im2colstep(x',sz, sz); ivan@113: D = [D ; nan(sz(1)*linewidth,size(D,2))]; ivan@113: sz(2) = sz(2)+linewidth; ivan@113: x = col2imstep(D(:,1:n*m),[m n].*sz,sz,sz); ivan@113: x = x'; ivan@113: x = x(1:end-linewidth,1:end-linewidth); ivan@113: ivan@113: if (highcontrast) ivan@113: for i = 0:n-1 ivan@113: for j = 0:m-1 ivan@113: x(i*sz(1)+1:i*sz(1)+sz(1)-linewidth, j*sz(2)+1:j*sz(2)+sz(2)-linewidth) = ... ivan@113: imnormalize(x(i*sz(1)+1:i*sz(1)+sz(1)-linewidth, j*sz(2)+1:j*sz(2)+sz(2)-linewidth)); ivan@113: end ivan@113: end ivan@113: else ivan@113: x = imnormalize(x); ivan@113: end ivan@113: ivan@113: x(isnan(x)) = linecolor; ivan@113: ivan@113: else ivan@113: ivan@113: x = col2imstep(D(:,1:n*m),[n m].*sz, sz, sz); ivan@113: ivan@113: if (highcontrast) ivan@113: for i = 0:n-1 ivan@113: for j = 0:m-1 ivan@113: x(i*sz(1)+1:i*sz(1)+sz(1), j*sz(2)+1:j*sz(2)+sz(2)) = ... ivan@113: imnormalize(x(i*sz(1)+1:i*sz(1)+sz(1), j*sz(2)+1:j*sz(2)+sz(2))); ivan@113: end ivan@113: end ivan@113: else ivan@113: x = imnormalize(x); ivan@113: end ivan@113: end ivan@113: ivan@113: ivan@113: if (nargout==0) ivan@113: imagesc(dictimg);colormap(gray);axis off; axis image; ivan@113: end