comparison Problems/generatePierreProblem.m @ 161:f42aa8bcb82f ivand_dev

debug and clean the SMALLbox Problems code
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Wed, 31 Aug 2011 12:02:19 +0100
parents
children 9c418bea7f6a
comparison
equal deleted inserted replaced
155:b14209313ba4 161:f42aa8bcb82f
1 function data=generatePierreProblem(src, trg, blocksize, dictsize);
2 %% Generate Pierre Villars Problem
3 %
4 % Pierre_Problem is a part of the SMALLbox and generates the problem
5 % suggested by Professor Pierre Vandergheynst on the SMALL meeting in
6 % Villars.
7 % The function takes as an input:
8 % - src - source image matrix (if not present function promts user for
9 % an image file) ,
10 % - trg - target image matrix (if not present function promts user for
11 % an image file) ,
12 % - blocksize - block (patch) vertical/horizontal dimension (default 8),
13 % - dictsize - dictionary size (default - all patches from target
14 % image).
15 %
16 % The output of the function is stucture with following fields:
17 % - srcname - source image name,
18 % - imageSrc - source image matrix,
19 % - trgname - target image name,
20 % - imageTrg - Target image matrix,
21 % - A - dictonary with patches from the source image,
22 % - b - measurement matrix (i.e. patches from target image to be
23 % represented in dictionary A,
24 % - m - size of patches (default 25),
25 % - n - number of patches to be represented,
26 % - p - dictionary size,
27 % - blocksize - block size (default [5 5]),
28 % - maxval - maximum value (default - 255)
29 % - sparse - if 1 SMALL_solve will keep solution matrix in sparse form,
30 % due to memory constrains.
31
32 %
33 % Centre for Digital Music, Queen Mary, University of London.
34 % This file copyright 2010 Ivan Damnjanovic.
35 %
36 % This program is free software; you can redistribute it and/or
37 % modify it under the terms of the GNU General Public License as
38 % published by the Free Software Foundation; either version 2 of the
39 % License, or (at your option) any later version. See the file
40 % COPYING included with this distribution for more information.
41 %% prompt user for images %%
42
43 % ask for source file name
44
45 TMPpath=pwd;
46 FS=filesep;
47 if ~ exist( 'src', 'var' ) || isempty(src)
48 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m'));
49 cd([pathstr1,FS,'data',FS,'images']);
50 [filename,pathname] = uigetfile({'*.png;'},'Select a source image');
51 [pathstr, name, ext, versn] = fileparts(filename);
52 data.srcname=name;
53 src = imread(filename);
54 src = double(src);
55 end;
56
57 % ask for target file name
58
59 if ~ exist( 'trg', 'var' ) || isempty(trg)
60 [filename,pathname] = uigetfile({'*.png;'},'Select a target image');
61 [pathstr, name, ext, versn] = fileparts(filename);
62 data.trgname=name;
63 trg = imread(filename);
64 trg = double(trg);
65 end;
66 cd(TMPpath);
67
68 %% set parameters %%
69
70 maxval = 255;
71 if ~ exist( 'blocksize', 'var' ) || isempty(blocksize),blocksize = 5;end
72
73 if ~ exist( 'dictsize', 'var' ) || isempty(dictsize),
74 dictsize = (size(src,1)-blocksize+1)*(size(src,2)-blocksize+1);
75 patch_idx=1:dictsize;
76 else
77 num_blocks_src=(size(src,1)-blocksize+1)*(size(src,2)-blocksize+1);
78 patch_idx=1:floor(num_blocks_src/dictsize):dictsize*floor(num_blocks_src/dictsize);
79 end
80
81 p = ndims(src);
82 if (p==2 && any(size(src)==1) && length(blocksize)==1)
83 p = 1;
84 end
85
86
87 % blocksize %
88 if (numel(blocksize)==1)
89 blocksize = ones(1,p)*blocksize;
90 end
91 %%
92 %% create dictionary data %%
93
94 S=im2colstep(src,blocksize);
95
96 for j= 1:size(S,2)
97 S(:,j)=S(:,j)./norm(S(:,j));
98 end
99
100 %% create measurement matrix %%
101
102 T=im2colstep(trg,blocksize, blocksize);
103
104 %% output structure %%
105
106 data.imageSrc = src;
107 data.imageTrg = trg;
108 data.A = S(:,patch_idx);
109 data.b = T;
110 data.m = size(T,1);
111 data.n = size(T,2);
112 data.p = size(data.A,2);
113 data.blocksize=blocksize;
114 data.maxval=maxval;
115
116 % keep coefficients matrix in sparse form and do not convert it to full.
117 % getting around out of memory problem when converting big matrix from
118 % sparse to full... (check SMALL_solve function)
119 data.sparse=1;
120
121