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