comparison Problems/Pierre_Problem.m @ 10:207a6ae9a76f version1.0

(none)
author idamnjanovic
date Mon, 22 Mar 2010 15:06:25 +0000
parents
children 0211faef9add
comparison
equal deleted inserted replaced
9:28f2b5fe3483 10:207a6ae9a76f
1 function data=Pierre_Problem(src, trg, blocksize, dictsize);
2 %%% Generate Pierre Problem
3 % Ivan Damnjanovic 2010
4 %
5 % Pierre_Problem is a part of the SMALLbox and generates the problem
6 % suggested by Professor Pierre Vandergheynst on the SMALL meeting in
7 % Villars.
8 % The function takes as an input:
9 % - src - source image matrix (if not present function promts user for
10 % an image file) ,
11 % - trg - target image matrix (if not present function promts user for
12 % an image file) ,
13 % - blocksize - block (patch) vertical/horizontal dimension (default 8),
14 % - dictsize - dictionary size (default - all patches from target
15 % image).
16 %
17 % The output of the function is stucture with following fields:
18 % - srcname - source image name,
19 % - imageSrc - source image matrix,
20 % - trgname - target image name,
21 % - imageTrg - Target image matrix,
22 % - A - dictonary with patches from the source image,
23 % - b - measurement matrix (i.e. patches from target image to be
24 % represented in dictionary A,
25 % - m - size of patches (default 25),
26 % - n - number of patches to be represented,
27 % - p - dictionary size,
28 % - blocksize - block size (default [5 5]),
29 % - maxval - maximum value (default - 255)
30 % - sparse - if 1 SMALL_solve will keep solution matrix in sparse form,
31 % due to memory constrains.
32
33 %% prompt user for images %%
34
35 %ask for source file name
36
37 TMPpath=pwd;
38 FS=filesep;
39 if ~ exist( 'src', 'var' ) || isempty(src)
40 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m'));
41 cd([pathstr1,FS,'data',FS,'images']);
42 [filename,pathname] = uigetfile({'*.png;'},'Select a source image');
43 [pathstr, name, ext, versn] = fileparts(filename);
44 data.srcname=name;
45 src = imread(filename);
46 src = double(src);
47 end;
48
49 %ask for target file name
50
51 if ~ exist( 'trg', 'var' ) || isempty(trg)
52 [filename,pathname] = uigetfile({'*.png;'},'Select a target image');
53 [pathstr, name, ext, versn] = fileparts(filename);
54 data.trgname=name;
55 trg = imread(filename);
56 trg = double(trg);
57 end;
58 cd(TMPpath);
59
60 %% set parameters %%
61
62 maxval = 255;
63 if ~ exist( 'blocksize', 'var' ) || isempty(blocksize),blocksize = 5;end
64
65 if ~ exist( 'dictsize', 'var' ) || isempty(dictsize),
66 dictsize = (size(src,1)-blocksize+1)*(size(src,2)-blocksize+1);
67 patch_idx=1:dictsize;
68 else
69 num_blocks_src=(size(src,1)-blocksize+1)*(size(src,2)-blocksize+1);
70 patch_idx=1:floor(num_blocks_src/dictsize):dictsize*floor(num_blocks_src/dictsize);
71 end
72
73 p = ndims(src);
74 if (p==2 && any(size(src)==1) && length(blocksize)==1)
75 p = 1;
76 end
77
78
79 % blocksize %
80 if (numel(blocksize)==1)
81 blocksize = ones(1,p)*blocksize;
82 end
83 %%
84 %% create dictionary data %%
85
86 S=im2col(src,blocksize,'sliding');
87
88 for j= 1:size(S,2)
89 S(:,j)=S(:,j)./norm(S(:,j));
90 end
91
92 %% create measurement matrix %%
93
94 T=im2col(trg,blocksize, 'distinct');
95
96 %% output structure %%
97
98 data.imageSrc = src;
99 data.imageTrg = trg;
100 data.A = S(:,patch_idx);
101 data.b = T;
102 data.m = size(T,1);
103 data.n = size(T,2);
104 data.p = size(data.A,2);
105 data.blocksize=blocksize;
106 data.maxval=maxval;
107
108 % geting around out of memory problem when converting big matrix from
109 % sparse to full... (check SMALL_solve function)
110 data.sparse=1;
111
112