Mercurial > hg > smallbox
changeset 232:15fd4c5be71a
merge
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Thu, 19 Apr 2012 15:55:14 +0100 |
parents | efe179d9757c (current diff) b1db9e090542 (diff) |
children | 88a5c02d20d3 |
files | Problems/generatePierre_Problem.m |
diffstat | 6 files changed, 48 insertions(+), 139 deletions(-) [+] |
line wrap: on
line diff
--- a/Problems/generatePierreProblem.m Wed Apr 11 16:28:46 2012 +0100 +++ b/Problems/generatePierreProblem.m Thu Apr 19 15:55:14 2012 +0100 @@ -88,18 +88,17 @@ if (numel(blocksize)==1) blocksize = ones(1,p)*blocksize; end -%% -%% create dictionary data %% -S=im2colstep(src,blocksize); +%% create dictionary data +S=im2col(src,blocksize,'sliding'); for j= 1:size(S,2) S(:,j)=S(:,j)./norm(S(:,j)); end -%% create measurement matrix %% - -T=im2colstep(trg,blocksize, blocksize); +%% observed patches matrix +% that are going to be decomposed on the dictionary +T=im2col(trg,blocksize, 'distinct'); %% output structure %%
--- a/Problems/generatePierre_Problem.m Wed Apr 11 16:28:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -function data=generatePierre_Problem(src, trg, blocksize, dictsize); -%% Generate Pierre Villars Problem -% -% Pierre_Problem is a part of the SMALLbox and generates the problem -% suggested by Professor Pierre Vandergheynst on the SMALL meeting in -% Villars. -% The function takes as an input: -% - src - source image matrix (if not present function promts user for -% an image file) , -% - trg - target image matrix (if not present function promts user for -% an image file) , -% - blocksize - block (patch) vertical/horizontal dimension (default 8), -% - dictsize - dictionary size (default - all patches from target -% image). -% -% The output of the function is stucture with following fields: -% - srcname - source image name, -% - imageSrc - source image matrix, -% - trgname - target image name, -% - imageTrg - Target image matrix, -% - A - dictonary with patches from the source image, -% - b - measurement matrix (i.e. patches from target image to be -% represented in dictionary A, -% - m - size of patches (default 25), -% - n - number of patches to be represented, -% - p - dictionary size, -% - blocksize - block size (default [5 5]), -% - maxval - maximum value (default - 255) -% - sparse - if 1 SMALL_solve will keep solution matrix in sparse form, -% due to memory constrains. - -% -% Centre for Digital Music, Queen Mary, University of London. -% This file copyright 2010 Ivan Damnjanovic. -% -% This program is free software; you can redistribute it and/or -% modify it under the terms of the GNU General Public License as -% published by the Free Software Foundation; either version 2 of the -% License, or (at your option) any later version. See the file -% COPYING included with this distribution for more information. -%% prompt user for images %% - -% ask for source file name - -TMPpath=pwd; -FS=filesep; -if ~ exist( 'src', 'var' ) || isempty(src) -[pathstr1, name, ext] = fileparts(which('SMALLboxSetup.m')); -cd([pathstr1,FS,'data',FS,'images']); -[filename,pathname] = uigetfile({'*.png;'},'Select a source image'); -[pathstr, name, ext] = fileparts(filename); -data.srcname=name; -src = imread(filename); -src = double(src); -end; - -% ask for target file name - -if ~ exist( 'trg', 'var' ) || isempty(trg) -[filename,pathname] = uigetfile({'*.png;'},'Select a target image'); -[pathstr, name, ext] = fileparts(filename); -data.trgname=name; -trg = imread(filename); -trg = double(trg); -end; -cd(TMPpath); - -%% set parameters %% - -maxval = 255; -if ~ exist( 'blocksize', 'var' ) || isempty(blocksize),blocksize = 5;end - -if ~ exist( 'dictsize', 'var' ) || isempty(dictsize), - dictsize = (size(src,1)-blocksize+1)*(size(src,2)-blocksize+1); - patch_idx=1:dictsize; -else - num_blocks_src=(size(src,1)-blocksize+1)*(size(src,2)-blocksize+1); - patch_idx=1:floor(num_blocks_src/dictsize):dictsize*floor(num_blocks_src/dictsize); -end - -p = ndims(src); -if (p==2 && any(size(src)==1) && length(blocksize)==1) - p = 1; -end - - -% blocksize % -if (numel(blocksize)==1) - blocksize = ones(1,p)*blocksize; -end -%% -%% create dictionary data %% - -S=im2colstep(src,blocksize); - -for j= 1:size(S,2) - S(:,j)=S(:,j)./norm(S(:,j)); -end - -%% create measurement matrix %% - -T=im2colstep(trg,blocksize, blocksize); - -%% output structure %% - -data.imageSrc = src; -data.imageTrg = trg; -data.A = S(:,patch_idx); -data.b = T; -data.m = size(T,1); -data.n = size(T,2); -data.p = size(data.A,2); -data.blocksize=blocksize; -data.maxval=maxval; - -% keep coefficients matrix in sparse form and do not convert it to full. -% getting around out of memory problem when converting big matrix from -% sparse to full... (check SMALL_solve function) -data.sparse=1; - -
--- a/config/SMALL_learn_config.m Wed Apr 11 16:28:46 2012 +0100 +++ b/config/SMALL_learn_config.m Thu Apr 19 15:55:14 2012 +0100 @@ -1,7 +1,10 @@ %% Configuration file used in SMALL_learn % -% Use this file to change the dictionary learning algorithms in SMALLBox -% Please refer to the documentation before editing this file +% Please DO NOT use this file to change the dictionary learning algorithms in SMALLBox +% If you want to change the dictionary learning algorithms +% create a copy of this file named 'SMALL_learn_config_local.m' +% +% Please refer to the documentation for further information % Centre for Digital Music, Queen Mary, University of London. % This file copyright 2009 Ivan Damnjanovic. @@ -73,7 +76,12 @@ DL.D(:,i)=DL.D(:,i)/norm(DL.D(:,i)); end D = DL.D; - + +%% +% Please do not make any changes to the 'SMALL_learn_config.m' file +% All the changes should be done to your local configuration file +% named 'SMALL_learn_config_local.m' +% % To introduce new dictionary learning technique put the files in % your Matlab path. Next, unique name <TolboxID> for your toolbox needs % to be defined and also prefferd API for toolbox functions <Preffered_API>
--- a/config/SMALL_solve_config.m Wed Apr 11 16:28:46 2012 +0100 +++ b/config/SMALL_solve_config.m Thu Apr 19 15:55:14 2012 +0100 @@ -1,7 +1,10 @@ %% Configuration file used in SMALL_solve % -% Use this file to change the solvers in SMALLBox -% Please refer to the documentation before editing this file +% Please DO NOT use this file to change the solvers used in SMALLBox +% If you want to change the solvers create a copy +% of this file named 'SMALL_learn_config_local.m' +% +% Please refer to the documentation for further information % Centre for Digital Music, Queen Mary, University of London. % This file copyright 2009 Ivan Damnjanovic. @@ -14,6 +17,7 @@ % %% + if strcmpi(solver.toolbox,'sparselab') y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']); elseif strcmpi(solver.toolbox,'sparsify') @@ -37,11 +41,11 @@ epsilon=solver.param.epsilon; maxatoms=solver.param.maxatoms; y = eval([solver.name,'(A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']); -% danieleb: added call to omp functions with fast implementation. + % danieleb: added call to omp functions with fast implementation. elseif (strcmpi(solver.toolbox, 'ompbox_fast')) DtX=A'*b; - XtX = sum(b.*b); - G=A'*A; + XtX = sum(b.*b); + G=A'*A; epsilon=solver.param.epsilon; maxatoms=solver.param.maxatoms; y = eval([solver.name,'(DtX, XtX, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']); @@ -71,6 +75,11 @@ [y, cost] = wrapper_mm_solver(b, A, solver.param); + %% + % Please do not make any changes to the 'SMALL_solve_config.m' file + % All the changes should be done to your local configuration file + % named 'SMALL_solve_config_local.m' + % % To introduce new sparse representation algorithm put the files in % your Matlab path. Next, unique name <TolboxID> for your toolbox and % prefferd API <Preffered_API> needs to be defined.
--- a/util/SMALL_learn.m Wed Apr 11 16:28:46 2012 +0100 +++ b/util/SMALL_learn.m Thu Apr 19 15:55:14 2012 +0100 @@ -28,8 +28,16 @@ start=cputime; tStart=tic; -% toolboxes configuration file -run(fullfile(SMALL_path, 'config/SMALL_learn_config.m')); +%% toolbox configuration +% test if there is a locally modified version of the config +% otherwise reads the "default" config file +if exist(fullfile(SMALL_path, 'config/SMALL_learn_config_local.m'), 'file') == 2 + printf('\n\nSMALL_learn: Using local configuration file.\n\n'); + run(fullfile(SMALL_path, 'config/SMALL_learn_config_local.m')); +else + printf('\n\nSMALL_learn: Using default configuration file.\n\n'); + run(fullfile(SMALL_path, 'config/SMALL_learn_config.m')); +end %% % Dictionary Learning time
--- a/util/SMALL_solve.m Wed Apr 11 16:28:46 2012 +0100 +++ b/util/SMALL_solve.m Thu Apr 19 15:55:14 2012 +0100 @@ -48,8 +48,14 @@ start=cputime; tStart=tic; -% solvers configuration file -run(fullfile(SMALL_path, 'config/SMALL_solve_config.m')); +%% solvers configuration +% test if there is a locally modified version of the config +% otherwise reads the "default" config file +if exist(fullfile(SMALL_path, 'config/SMALL_solve_config_local.m'), 'file') == 2 + run(fullfile(SMALL_path, 'config/SMALL_solve_config_local.m')); +else + run(fullfile(SMALL_path, 'config/SMALL_solve_config.m')); +end %% % Sparse representation time