Mercurial > hg > smallbox
changeset 178:4ea4badb2266 danieleb
added ramirez dl (to be completed) and MOCOD dictionary update
author | Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk> |
---|---|
date | Thu, 17 Nov 2011 11:22:17 +0000 |
parents | 714fa7b8c1ad (current diff) 775caafd5651 (diff) |
children | 989b7d78e1c8 |
files | .hgtags util/SMALL_solve.m |
diffstat | 34 files changed, 1186 insertions(+), 152 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Thu Nov 17 11:18:25 2011 +0000 +++ b/.hgtags Thu Nov 17 11:22:17 2011 +0000 @@ -5,4 +5,4 @@ 19e0af5709140e163faaf9d8cf4b83a664be1edc release_1.5 a4d0977d45956b96579a3ed83a4e6a1869ee6055 danieleb a4d0977d45956b96579a3ed83a4e6a1869ee6055 danieleb -0000000000000000000000000000000000000000 danieleb +0000000000000000000000000000000000000000 danieleb \ No newline at end of file
--- a/DL/Majorization Minimization DL/wrapper_mm_solver.m Thu Nov 17 11:18:25 2011 +0000 +++ b/DL/Majorization Minimization DL/wrapper_mm_solver.m Thu Nov 17 11:22:17 2011 +0000 @@ -33,7 +33,7 @@ if isfield(param, 'to') to = param.to; else - to = .1+svds(A,1); + to = .1+(svds(A,1))^2; end % lambda - Lagrangian multiplier. (regulates shrinkage) @@ -65,7 +65,7 @@ if isfield(param, 'map') map = param.map; else - map = 1; + map = 0; end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Problems/AMT_reconstruct.m Thu Nov 17 11:22:17 2011 +0000 @@ -0,0 +1,117 @@ +function reconstructed=AMT_reconstruct(V, Problem) +%% Reconstruction of midi file from representation in the given dictionary +% +% SMALL_midiGenerate is a part of SMALLbox and can be use to reconstruct +% a midi file given representation of the training set (V) in the +% dictionary Problem.A. +% Output is reconstructed structure with two fields: +% - reconstructed.notes - matrix with transcribed notes +% - reconstructed.midi - midi representation of transcription + +% +% Centre for Digital Music, Queen Mary, University of London. +% This file copyright 2009 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. +%% +U=Problem.A; % Dictionary used for representation +fs=Problem.fs; % Sampling rate +f=Problem.f; % vector of frequencies at wihch spectrogram is computed + +ts=(Problem.windowSize*(1-Problem.overlap))/fs; %size of an analysis frame in seconds + +%% +% Components pitch estimation using modified SWIPE algorithm by Arthuro +% Camacho +% +% Columns of matrix U are spectrograms of the notes learned from the +% training set. We are estimating pitches of these notes by also +% restricting pitch values to the one of the 88 piano notes. + +pitch=zeros(size(U,2),1); + +for i=1:size(U,2) + + pitch(i) = SMALL_swipe(U(:,i),fs, f, [27.50 8192], 1/12); + +end + +%% +% If some of columns of U have the same pitch, their contribution to the +% score (matrix V) is summed. + +[Ps,idx]=sort(pitch); +ndp=1; +Pd(ndp)=Ps(1); +Vnew(ndp,:)=V(idx(1),:); +for i=2:88 + if Ps(i)> Ps(i-1) + + ndp=ndp+1; + Vnew(ndp,:)=V(idx(i),:); + Pd(ndp)=Ps(i); + + else + Vnew(ndp,:)=Vnew(ndp,:)+V(idx(i),:); + end +end +%% +% Generate midi matrix + +midx=0; +for i=1:ndp + + % Threshold for finding onsets and offsets of notes + + thr=mean(Vnew(i,:));%+std(Vnew(i,:)); + + if(Pd(i)~=0) + for j=1:size(Vnew,2) + if Vnew(i,j)<thr + Vnew(i,j)=0; + if(j>1) + if (Vnew(i,j-1)==1) + try + M(midx,6)=(j-1)*ts; + if (M(midx,6)-M(midx,5))<2*ts + midx=midx-1; + end + catch + pause; + end + end + end + else + Vnew(i,j)=1; + if(j>1) + if (Vnew(i,j-1)==0) + midx=midx+1; + M(midx,1)=1; + M(midx,2)=1; + M(midx,3)=69 +round( 12 *log2(Pd(i)/440)); + M(midx,4)=80; + M(midx,5)=(j-1)*ts; + end + else + midx=midx+1; + M(midx,1)=1; + M(midx,2)=1; + M(midx,3)=69 + round(12 *log2(Pd(i)/440)); + M(midx,4)=80; + M(midx,5)=0; + end + end + end + if M(midx,6)==0 + M(midx,6)=(j-1)*ts; + end + end +end + +M=sortrows(M,5); +reconstructed.notes=M; +reconstructed.midi = matrix2midi(M);
--- a/Problems/AudioDeclipping_reconstruct.m Thu Nov 17 11:18:25 2011 +0000 +++ b/Problems/AudioDeclipping_reconstruct.m Thu Nov 17 11:22:17 2011 +0000 @@ -1,8 +1,15 @@ -function reconstructed=AudioDeclipping_reconstruct(y, Problem, SparseDict) +function reconstructed = AudioDeclipping_reconstruct(y, Problem) %% Audio declipping Problem reconstruction function % % This reconstruction function is using sparse representation y % in dictionary Problem.A to reconstruct declipped audio. +% The output structure has following fields: +% audioAllSamples - signal with all samples taken from reconstructed +% signal +% audioOnlyClipped - only clipped samples are reconstructed, +% others are taken from original signal +% snrAll - psnr of whole signal +% snrMiss - psnr of the reconstructed clipped samples % % [1] I. Damnjanovic, M. E. P. Davies, and M. P. Plumbley "SMALLbox - an % evaluation framework for sparse representations and dictionary
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Problems/AudioDenoise_reconstruct.m Thu Nov 17 11:22:17 2011 +0000 @@ -0,0 +1,53 @@ +function reconstructed=AudioDenoise_reconstruct(y, Problem) +%% Audio denoising Problem reconstruction function +% +% This reconstruction function is using sparse representation y +% in dictionary Problem.A to reconstruct denoised audio. +% The output structre has following fields: +% audio - denoised audio signal +% psnr - psnr of the reconstructed audio signal +% +% [1] I. Damnjanovic, M. E. P. Davies, and M. P. Plumbley "SMALLbox - an +% evaluation framework for sparse representations and dictionary +% learning algorithms," V. Vigneron et al. (Eds.): LVA/ICA 2010, +% Springer-Verlag, Berlin, Germany, LNCS 6365, pp. 418-425 + +% +% Centre for Digital Music, Queen Mary, University of London. +% This file copyright 2011 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. +%% + +windowSize = Problem.windowSize; +overlap = Problem.overlap; +ws = Problem.ws(windowSize); +wa = Problem.wa(windowSize); + +A = Problem.A; + +orig = Problem.Original; +noisy = Problem.Noisy; + + +% reconstruct audio frames + +xFrames = diag(ws)*(A*y); +wNormFrames = (ws.*wa)'*ones(1,size(xFrames,2)); + +% overlap and add + +rec = col2imstep(xFrames, size(noisy), [windowSize 1], [windowSize*overlap 1]); +wNorm = col2imstep(wNormFrames, size(noisy), [windowSize 1], [windowSize*overlap 1]); +wNorm(find(wNorm==0)) = 1; +recN = rec./wNorm; + +%% output structure image+psnr %% +reconstructed.audio = recN; +reconstructed.psnr = 20*log10(sqrt(numel(orig)) / norm(orig - reconstructed.audio)); + +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Problems/ImageDenoise_reconstruct.m Thu Nov 17 11:22:17 2011 +0000 @@ -0,0 +1,66 @@ +function reconstructed=ImageDenoise_reconstruct(y, Problem, SparseDict) +%% Image Denoising Problem reconstruction function +% +% This reconstruction function is using sparse representation y +% in dictionary Problem.A to reconstruct the patches of the denoised +% image. + +% +% Centre for Digital Music, Queen Mary, University of London. +% This file copyright 2009 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. +%% + + +% stepsize % +if (isfield(Problem,'stepsize')) + stepsize = Problem.stepsize; + if (numel(stepsize)==1) + stepsize = ones(1,2)*stepsize; + end +else + stepsize = ones(1,2); +end +if (any(stepsize<1)) + error('Invalid step size.'); +end + +% lambda % +if (isfield(Problem,'lambda')) + lambda = Problem.lambda; +else + lambda = Problem.maxval/(10*Problem.sigma); +end +if exist('SparseDict','var')&&(SparseDict==1) + if issparse(Problem.A) + A = Problem.A; + else + A = sparse(Problem.A); + end + cl_samp=add_dc(dictsep(Problem.basedict,A,y), Problem.b1dc,'columns'); +else + cl_samp=add_dc(Problem.A*y, Problem.b1dc,'columns'); +end +% combine the patches into reconstructed image +cl_im=col2imstep(cl_samp, size(Problem.Noisy), Problem.blocksize); + +cnt = countcover(size(Problem.Noisy),Problem.blocksize,stepsize); + +im = (cl_im+lambda*Problem.Noisy)./(cnt + lambda); +% y(y~=0)=1; +% numD=sum(y,2); +% nnzy=sum(y,1); +% figure(200);plot(sort(numD)); +% figure(201);plot(sort(nnzy)); +[v.RMSErn, v.RMSEcd, v.rn_im, v.cd_im]=SMALL_vmrse_type2(Problem.Original, Problem.Noisy, im); +%% output structure image+psnr %% +reconstructed.Image=im; +reconstructed.psnr = 20*log10(Problem.maxval * sqrt(numel(Problem.Original(:))) / norm(Problem.Original(:)-im(:))); +reconstructed.vmrse=v; +reconstructed.ssim=SMALL_ssim_index(Problem.Original, im); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Problems/generateAMTProblem.m Thu Nov 17 11:22:17 2011 +0000 @@ -0,0 +1,91 @@ +function data = generateAMTProblem(nfft, windowSize, overlap) +%% Generate Automatic Music Transcription Problem +% +% generateAMT_Learning_Problem is a part of the SMALLbox and generates +% a problem that can be used for comparison of Dictionary Learning/Sparse +% Representation techniques in automatic music transcription scenario. +% The function prompts a user for an audio file (mid, wav, mat) reads it +% and generates a spectrogram given fft size (default nfft=4096), analysis +% window size (windowSize=2822), and analysis window overlap (overlap = +% 0.5). +% +% The output of the function is stucture with following fields: +% b - matrix with magnitudes of the spectrogram +% f - vector of frequencies at wihch spectrogram is computed +% windowSize - analysis window size +% overlap - analysis window overlap +% fs - sampling frequency +% m - number of frequenciy points in spectrogram +% n - number of time points in the spectrogram +% p - number of dictionary elements to be learned (eg 88 for piano) +% notesOriginal - notes of the original audio to be used for +% comparison (if midi of the original exists) +% name - name of the audio file to transcribe + +% Centre for Digital Music, Queen Mary, University of London. +% This file copyright 2009 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. +% +%% +FS=filesep; +if ~ exist( 'nfft', 'var' ) || isempty(nfft), nfft = 4096; end +if ~ exist( 'windowSize', 'var' ) || isempty(windowSize), windowSize = 2822; end +if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 0.5; end + +%% +%ask for file name +TMPpath=pwd; +[pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m')); +cd([pathstr1,FS,'data',FS,'audio']); +[filename,pathname] = uigetfile({'*.mat; *.mid; *.wav'},'Select a file to transcribe'); +[pathstr, name, ext, versn] = fileparts(filename); +data.name=name; + +data.notesOriginal=[]; + +if strcmp(ext,'.mid') + midi=readmidi(filename); + data.notesOriginal=midiInfo(midi); + y=midi2audio(midi); + wavwrite(y, 44100, 16, 'temp.wav'); + [x.signal, x.fs, x.nbits]=wavread('temp.wav'); + delete('temp.wav'); +elseif strcmp(ext,'.wav') + cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); + filename1=[name, '.mid']; + if exist(filename1, 'file') + midi=readmidi(filename1); + data.notesOriginal=midiInfo(midi); + end + cd([pathstr1,FS, 'data', FS, 'audio', FS, 'wav']); + [x.signal, x.fs, x.nbits]=wavread(filename); +else + cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); + filename1=[name, '.mid']; + if exist(filename1, 'file') + midi=readmidi(filename1); + data.notesOriginal=midiInfo(midi); + end + cd([pathstr1,FS, 'data', FS, 'audio', FS, 'mat']); + x=load([pathname,filename]); +end +%% +[X, frX]=spectrogram(x.signal, hanning(windowSize), overlap*windowSize, nfft, x.fs); +%% +data.b=abs(X); +data.f=frX; +data.windowSize=windowSize; +data.overlap=overlap; +data.fs=x.fs; +data.m=size(X,1); +data.n=size(X,2); + +data.p=88; %number of dictionary elements (ie notes to recover) +cd(TMPpath); + +end
--- a/Problems/generateAudioDeclippingProblem.m Thu Nov 17 11:18:25 2011 +0000 +++ b/Problems/generateAudioDeclippingProblem.m Thu Nov 17 11:22:17 2011 +0000 @@ -5,6 +5,35 @@ % Audio declipping is a problem proposed in Audio Inpaining Toolbox and % in [2]. % +% The function takes as an optional input +% soundfile - name of the file +% clippingLevel - (default 0.6) +% windowSize - 1D frame size (eg 512) +% overlap - ammount of overlaping frames between 0 and 1 +% wa,ws,wd - analisys, synthesis and dictionary window functions +% +% Dict_fun - function to be used to generate dictionary +% redundancyFactor - overcompletness of dictionary (default 2) +% +% The function outputs the structure with following fields: +% original - original signal +% clipped - clipped signal +% clipMask - mask indicating clipped samples +% clippingLevel - (default 0.6) +% Upper_Limit - maximum value of original data +% fs - sample rate of the original signal in Hertz +% nbits - the number of bits per sample +% sigma - added noise level +% B - dictionary to be used for sparse representation +% M - measurement matrix (non-clipped data in b) +% b - matrix of clipped frames +% m - size od dictionary atom +% n - number of frames to be represented +% p - number of atoms in dictionary +% windowSize - 1D frame size (eg 512) +% overlap - ammount of overlaping frames between 0 and 1 +% wa,ws, wd - analisys, synthesis and dictionary window functions +% % [1] I. Damnjanovic, M. E. P. Davies, and M. P. Plumbley "SMALLbox - an % evaluation framework for sparse representations and dictionary % learning algorithms," V. Vigneron et al. (Eds.): LVA/ICA 2010, @@ -103,7 +132,7 @@ data.fs = x.fs; data.nbits = x.nbits; -data.Upper_Limit = max(solutiondata.XClean); +data.Upper_Limit = max(solutionData.xClean); [data.m, data.n] = size(x_clip); data.p = windowSize*redundancyFactor; %number of dictionary elements
--- a/Problems/generateAudioDenoiseProblem.m Thu Nov 17 11:18:25 2011 +0000 +++ b/Problems/generateAudioDenoiseProblem.m Thu Nov 17 11:22:17 2011 +0000 @@ -1,20 +1,40 @@ -function data=generateAudioDenoiseProblem(au, trainnum, blocksize, dictsize, overlap, sigma, gain, maxval, initdict); -%% Audio Denoising Problem - needs revision, not yet finalised +function data = generateAudioDenoiseProblem(soundfile, sigma, windowSize,... + overlap, wa, ws, trainnum, redundancyFactor, initdict) +%% Audio Denoising Problem % % generateAudioDenoiseProblem is part of the SMALLbox and generate a % problem for comaprison of Dictionary Learning/Sparse Representation -% techniques in audio denoising scenario. It is based on KSVD image -% denoise demo by Ron Rubinstein (see bellow). -% The fuction takes as an optional input -% au - audio samples to be denoised -% trainnum - number of frames for training -% blocksize - 1D frame size (eg 512) -% dictsize - number of atoms to be trained -% overlap - ammount of overlaping frames between 0 and 1 +% techniques in audio denoising scenario. +% +% The function takes as an optional input +% soundfile - name of the file +% sigma - noise level (dB) +% windowSize - 1D frame size (eg 512) +% overlap - ammount of overlaping frames between 0 and 1 +% wa,ws - analisys and synthesis window functions +% +% trainnum - number of frames for training +% redundancyFactor - overcompletness of dictionary (default 2) +% initdict - initial dictionary % +% The function outputs the structure with following fields: +% Original - original signal +% Noisy - signal with added noise +% fs - sample rate of the original signal in Hertz +% nbits - the number of bits per sample +% sigma - added noise level +% b - matrix of training samples for dictionary learning +% b1 - matrix containing all frames for reconstruction step +% m - size od dictionary atom +% n - number of frames for training +% p - number of atoms in dictionary +% windowSize - 1D frame size (eg 512) +% overlap - ammount of overlaping frames between 0 and 1 +% wa,ws - analisys and synthesis window functions +% initdict - initial dictionary % Centre for Digital Music, Queen Mary, University of London. -% This file copyright 2010 Ivan Damnjanovic. +% This file copyright 2011 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 @@ -30,67 +50,69 @@ disp(' '); FS=filesep; -if ~ exist( 'sigma', 'var' ) || isempty(sigma), sigma = 26.74; end -if ~ exist( 'gain', 'var' ) || isempty(gain), gain = 1.15; end -if ~ exist( 'initdict', 'var' ) || isempty(initdict), initdict = 'odct'; end -if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 15/16; end %% prompt user for wav file %% %ask for file name TMPpath=pwd; -if ~ exist( 'au', 'var' ) || isempty(au) +if ~ exist( 'soundfile', 'var' ) || isempty(soundfile) + %ask for file name [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m')); - cd([pathstr1,FS,'data',FS,'audio',FS,'wav']); - [filename,pathname] = uigetfile({'*.wav;'},'Select a wav file'); + cd([pathstr1,FS,'data',FS,'audio']); + [filename,pathname] = uigetfile({'*.mat; *.mid; *.wav'},'Select a file to transcribe'); [pathstr, name, ext, versn] = fileparts(filename); data.name=name; - - au = wavread(filename); - au = mean(au,2); % turn it into mono. -end; -if ~ exist( 'maxval', 'var' ) || isempty(maxval), maxval = max(au); end -%% generate noisy audio %% - -disp(' '); -disp('Generating noisy audio...'); -sigma = max(au)/10^(sigma/20); -n = randn(size(au)) .* sigma; -aunoise = au + n;% here we can load noise audio if available - % for example: wavread('icassp06_x.wav');% - - + if strcmp(ext,'.mid') + midi=readmidi(filename); +% data.notesOriginal=midiInfo(midi); + y=midi2audio(midi); + wavwrite(y, 44100, 16, 'temp.wav'); + [x.signal, x.fs, x.nbits]=wavread('temp.wav'); + delete('temp.wav'); + elseif strcmp(ext,'.wav') +% cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); +% filename1=[name, '.mid']; +% if exist(filename1, 'file') +% midi=readmidi(filename1); +% data.notesOriginal=midiInfo(midi); +% end + cd([pathstr1,FS, 'data', FS, 'audio', FS, 'wav']); + [x.signal, x.fs, x.nbits]=wavread(filename); + else +% cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); +% filename1=[name, '.mid']; +% if exist(filename1, 'file') +% midi=readmidi(filename1); +% data.notesOriginal=midiInfo(midi); +% end + cd([pathstr1,FS, 'data', FS, 'audio', FS, 'mat']); + x=load([pathname,filename]); + end +else + [x.signal, x.fs, x.nbits]=wavread(soundfile); + [pathstr, name, ext, versn] = fileparts(soundfile); + data.name=name; +end %% set parameters %% +if ~ exist( 'sigma', 'var' ) || isempty(sigma), sigma = 0.2; end -x = aunoise; -if ~ exist( 'blocksize', 'var' ) || isempty(blocksize),blocksize = 512;end -if ~ exist( 'dictsize', 'var' ) || isempty(dictsize), dictsize = 2048;end +if ~ exist( 'windowSize', 'var' ) || isempty(windowSize), windowSize = 256;end +if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 0.5; end +if ~ exist( 'wa', 'var' ) || isempty(wa), wa = @wSine; end % Analysis window +if ~ exist( 'ws', 'var' ) || isempty(ws), ws = @wSine; end % Synthesis window -if ~ exist( 'trainnum', 'var' ) || isempty(trainnum),trainnum = (size(x,1)-blocksize+1);end +if ~ exist( 'redundancyFactor', 'var' ) || isempty(windowSize),... + redundancyFactor = 2;end +if ~ exist( 'initdict', 'var' ) || isempty(initdict),... + initdict = 'odct'; end +if ~ exist( 'trainnum', 'var' ) || isempty(trainnum), ... + trainnum = 16*redundancyFactor*windowSize;end - - - -p=1; - - -% -% msgdelta = 5; -% -% verbose = 't'; -% if (msgdelta <= 0) -% verbose=''; -% msgdelta = -1; -% end -% -% -% % initial dictionary % -% if (strcmpi(initdict,'odct')) - initdict = odctndict(blocksize,dictsize,p); + initdict = odctndict(windowSize, redundancyFactor*windowSize, 1); elseif (strcmpi(initdict,'data')) clear initdict; % causes initialization using random examples else @@ -98,45 +120,31 @@ end if exist( 'initdict', 'var' ) - initdict = initdict(:,1:dictsize); + initdict = initdict(:,1:redundancyFactor*windowSize); end -% noise mode % -% if (isfield(params,'noisemode')) -% switch lower(params.noisemode) -% case 'psnr' -% sigma = maxval / 10^(params.psnr/20); -% case 'sigma' -% sigma = params.sigma; -% otherwise -% error('Invalid noise mode specified'); -% end -% elseif (isfield(params,'sigma')) -% sigma = params.sigma; -% elseif (isfield(params,'psnr')) -% sigma = maxval / 10^(params.psnr/20); -% else -% error('Noise strength not specified'); -% end - -% params.Edata = sqrt(prod(blocksize)) * sigma * gain; % target error for omp -% params.codemode = 'error'; -% -% params.sigma = sigma; -% params.noisemode = 'sigma'; -% -% -% % make sure test data is not present in params -% if (isfield(params,'testdata')) -% params = rmfield(params,'testdata'); -% end - - %%%% create training data %%% +%% generate noisy audio %% -X = buffer( x(1:trainnum),blocksize, overlap*blocksize); +disp(' '); +disp('Generating noisy audio...'); +x.signal = x.signal/max(abs(x.signal(:)))*0.99999; +n = randn(size(x.signal)) .* sigma; + +xnoise = x.signal + n;% here we can load noise audio if available + % for example: wavread('icassp06_x.wav');% + + + + +X = im2colstep(xnoise,[windowSize 1],[overlap*windowSize 1]); +X = diag(wa(windowSize)) * X; + + + + % remove dc in blocks to conserve memory % % bsize = 2000; @@ -144,17 +152,32 @@ % blockids = i : min(i+bsize-1,size(X,2)); % X(:,blockids) = remove_dc(X(:,blockids),'columns'); % end -data.Original = au; -data.Noisy = aunoise; -data.b = X; -data.m = size(X,1); -data.n = size(X,2); -data.p = dictsize; -data.blocksize=blocksize; +data.Original = x.signal; +data.Noisy = xnoise; +data.fs = x.fs; +data.nbits = x.nbits; + data.sigma = sigma; -data.gain = gain; -data.maxval = maxval; + + +if (trainnum<size(X,2)) + p = randperm(size(X,2)); + p=sort(p(1:trainnum)); + data.b = X(:,p); +else + data.b = X; +end + +data.b1 = X; +[data.m, data.n] = size(data.b); +data.p = redundancyFactor*windowSize; + +data.windowSize = windowSize; +data.overlap = overlap; +data.ws = ws; +data.wa = wa; + data.initdict= initdict; -data.signalDim=1; + cd(TMPpath);
--- a/Problems/generateImageDenoiseProblem.m Thu Nov 17 11:18:25 2011 +0000 +++ b/Problems/generateImageDenoiseProblem.m Thu Nov 17 11:22:17 2011 +0000 @@ -1,4 +1,5 @@ -function data=generateImageDenoiseProblem(im, trainnum, blocksize, dictsize, sigma, gain, maxval, initdict); +function data = generateImageDenoiseProblem(im, trainnum, blocksize,... + dictsize, sigma, gain, maxval, initdict) %% Generate Image Denoising Problem % % generateImageDenoiseProblem is a part of the SMALLbox and generates
--- a/Problems/generateMyDummyProblem.m Thu Nov 17 11:18:25 2011 +0000 +++ b/Problems/generateMyDummyProblem.m Thu Nov 17 11:22:17 2011 +0000 @@ -13,7 +13,7 @@ %% Change copyright notice as appropriate: % Centre for Digital Music, Queen Mary, University of London. -% This file copyright 2009 Ivan Damnjanovic. +% This file copyright 2011 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Problems/generatePierreProblem.m Thu Nov 17 11:22:17 2011 +0000 @@ -0,0 +1,121 @@ +function data=generatePierreProblem(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, versn] = fileparts(which('SMALLboxSetup.m')); +cd([pathstr1,FS,'data',FS,'images']); +[filename,pathname] = uigetfile({'*.png;'},'Select a source image'); +[pathstr, name, ext, versn] = 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, versn] = 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; + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/ALPS solvers tests/SMALL_ImgDenoise_DL_test_KSVDvsTwoStepALPSandMahile.m Thu Nov 17 11:22:17 2011 +0000 @@ -0,0 +1,288 @@ +%% Dictionary Learning for Image Denoising - KSVD vs Recursive Least Squares +% +% This file contains an example of how SMALLbox can be used to test different +% dictionary learning techniques in Image Denoising problem. +% It calls generateImageDenoiseProblem that will let you to choose image, +% add noise and use noisy image to generate training set for dictionary +% learning. +% Two dictionary learning techniques were compared: +% - KSVD - M. Elad, R. Rubinstein, and M. Zibulevsky, "Efficient +% Implementation of the K-SVD Algorithm using Batch Orthogonal +% Matching Pursuit", Technical Report - CS, Technion, April 2008. +% - RLS-DLA - Skretting, K.; Engan, K.; , "Recursive Least Squares +% Dictionary Learning Algorithm," Signal Processing, IEEE Transactions on, +% vol.58, no.4, pp.2121-2130, April 2010 +% + + +% Centre for Digital Music, Queen Mary, University of London. +% This file copyright 2011 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. +% +%% + + + +% If you want to load the image outside of generateImageDenoiseProblem +% function uncomment following lines. This can be useful if you want to +% denoise more then one image for example. +% Here we are loading test_image.mat that contains structure with 5 images : lena, +% barbara,boat, house and peppers. +clear; +TMPpath=pwd; +FS=filesep; +[pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m')); +cd([pathstr1,FS,'data',FS,'images']); +load('test_image.mat'); +cd(TMPpath); + +% Deffining the noise levels that we want to test + +noise_level=[10 20 25 50 100]; + +% Here we loop through different noise levels and images + +for noise_ind=4:4 +for im_num=1:1 + +% Defining Image Denoising Problem as Dictionary Learning +% Problem. As an input we set the number of training patches. + +SMALL.Problem = generateImageDenoiseProblem(test_image(im_num).i, 40000, '',256, noise_level(noise_ind)); +SMALL.Problem.name=int2str(im_num); + +Edata=sqrt(prod(SMALL.Problem.blocksize)) * SMALL.Problem.sigma * SMALL.Problem.gain; +maxatoms = floor(prod(SMALL.Problem.blocksize)/2); + +% results structure is to store all results + +results(noise_ind,im_num).noisy_psnr=SMALL.Problem.noisy_psnr; + +%% +% Use KSVD Dictionary Learning Algorithm to Learn overcomplete dictionary + +% Initialising Dictionary structure +% Setting Dictionary structure fields (toolbox, name, param, D and time) +% to zero values + +SMALL.DL(1)=SMALL_init_DL(); + +% Defining the parameters needed for dictionary learning + +SMALL.DL(1).toolbox = 'KSVD'; +SMALL.DL(1).name = 'ksvd'; + +% Defining the parameters for KSVD +% In this example we are learning 256 atoms in 20 iterations, so that +% every patch in the training set can be represented with target error in +% L2-norm (Edata) +% Type help ksvd in MATLAB prompt for more options. + + +SMALL.DL(1).param=struct(... + 'Edata', Edata,... + 'initdict', SMALL.Problem.initdict,... + 'dictsize', SMALL.Problem.p,... + 'exact', 1, ... + 'iternum', 20,... + 'memusage', 'high'); + +% Learn the dictionary + +SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1)); + +% Set SMALL.Problem.A dictionary +% (backward compatiblity with SPARCO: solver structure communicate +% only with Problem structure, ie no direct communication between DL and +% solver structures) + +SMALL.Problem.A = SMALL.DL(1).D; +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); + +%% +% Initialising solver structure +% Setting solver structure fields (toolbox, name, param, solution, +% reconstructed and time) to zero values + +SMALL.solver(1)=SMALL_init_solver; + +% Defining the parameters needed for image denoising + +SMALL.solver(1).toolbox='ompbox'; +SMALL.solver(1).name='omp2'; +SMALL.solver(1).param=struct(... + 'epsilon',Edata,... + 'maxatoms', maxatoms); + +% Denoising the image - find the sparse solution in the learned +% dictionary for all patches in the image and the end it uses +% reconstruction function to reconstruct the patches and put them into a +% denoised image + +SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1)); + +% Show PSNR after reconstruction + +SMALL.solver(1).reconstructed.psnr + +%% +% For comparison purposes we will denoise image with overcomplete DCT +% here +% Set SMALL.Problem.A dictionary to be oDCT (i.e. Problem.initdict - +% since initial dictionaruy is already set to be oDCT when generating the +% denoising problem + + +% Initialising solver structure +% Setting solver structure fields (toolbox, name, param, solution, +% reconstructed and time) to zero values + +SMALL.solver(2)=SMALL_init_solver('ALPS','AgebraicPursuit','',1); + +% Defining the parameters needed for image denoising + +SMALL.solver(2).param=struct(... + 'tolerance',1e-05,... + 'sparsity', 32,... + 'mode', 0,... + 'memory', 1,... + 'iternum', 50); + +% Initialising Dictionary structure +% Setting Dictionary structure fields (toolbox, name, param, D and time) +% to zero values + +SMALL.DL(2)=SMALL_init_DL('TwoStepDL', 'Mailhe', '', 1); + + +% Defining the parameters for MOD +% In this example we are learning 256 atoms in 20 iterations, so that +% every patch in the training set can be represented with target error in +% L2-norm (EData) +% Type help ksvd in MATLAB prompt for more options. + + +SMALL.DL(2).param=struct(... + 'solver', SMALL.solver(2),... + 'initdict', SMALL.Problem.initdict,... + 'dictsize', SMALL.Problem.p,... + 'iternum', 40,... + 'show_dict', 1); + +% Learn the dictionary + +SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); + +% Set SMALL.Problem.A dictionary +% (backward compatiblity with SPARCO: solver structure communicate +% only with Problem structure, ie no direct communication between DL and +% solver structures) + +SMALL.Problem.A = SMALL.DL(2).D; +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); + +% Denoising the image - find the sparse solution in the learned +% dictionary for all patches in the image and the end it uses +% reconstruction function to reconstruct the patches and put them into a +% denoised image + +SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); + +%% +% In the b1 field all patches from the image are stored. For RLS-DLA we +% will first exclude all the patches that have l2 norm smaller then +% threshold and then take min(40000, number_of_remaining_patches) in +% ascending order as our training set (SMALL.Problem.b) + +X=SMALL.Problem.b1; +X_norm=sqrt(sum(X.^2, 1)); +[X_norm_sort, p]=sort(X_norm); +p1=p(X_norm_sort>Edata); +if size(p1,2)>40000 + p2 = randperm(size(p1,2)); + p2=sort(p2(1:40000)); + size(p2,2) + SMALL.Problem.b=X(:,p1(p2)); +else + size(p1,2) + SMALL.Problem.b=X(:,p1); + +end + +% Forgetting factor for RLS-DLA algorithm, in this case we are using +% fixed value + +lambda=0.9998 + +% Use Recursive Least Squares +% to Learn overcomplete dictionary + +% Initialising Dictionary structure +% Setting Dictionary structure fields (toolbox, name, param, D and time) +% to zero values + +SMALL.DL(3)=SMALL_init_DL(); + +% Defining fields needed for dictionary learning + +SMALL.DL(3).toolbox = 'SMALL'; +SMALL.DL(3).name = 'SMALL_rlsdla'; +SMALL.DL(3).param=struct(... + 'Edata', Edata,... + 'initdict', SMALL.Problem.initdict,... + 'dictsize', SMALL.Problem.p,... + 'forgettingMode', 'FIX',... + 'forgettingFactor', lambda,... + 'show_dict', 1000); + + +SMALL.DL(3) = SMALL_learn(SMALL.Problem, SMALL.DL(3)); + +% Initialising solver structure +% Setting solver structure fields (toolbox, name, param, solution, +% reconstructed and time) to zero values + +SMALL.Problem.A = SMALL.DL(3).D; +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); + +SMALL.solver(3)=SMALL_init_solver; + +% Defining the parameters needed for image denoising + +SMALL.solver(3).toolbox='ompbox'; +SMALL.solver(3).name='omp2'; +SMALL.solver(3).param=struct(... + 'epsilon',Edata,... + 'maxatoms', maxatoms); + + +SMALL.solver(3)=SMALL_solve(SMALL.Problem, SMALL.solver(3)); + +SMALL.solver(3).reconstructed.psnr + + +% show results % + +SMALL_ImgDeNoiseResult(SMALL); + +results(noise_ind,im_num).psnr.ksvd=SMALL.solver(1).reconstructed.psnr; +results(noise_ind,im_num).psnr.odct=SMALL.solver(2).reconstructed.psnr; +results(noise_ind,im_num).psnr.rlsdla=SMALL.solver(3).reconstructed.psnr; +results(noise_ind,im_num).vmrse.ksvd=SMALL.solver(1).reconstructed.vmrse; +results(noise_ind,im_num).vmrse.odct=SMALL.solver(2).reconstructed.vmrse; +results(noise_ind,im_num).vmrse.rlsdla=SMALL.solver(3).reconstructed.vmrse; +results(noise_ind,im_num).ssim.ksvd=SMALL.solver(1).reconstructed.ssim; +results(noise_ind,im_num).ssim.odct=SMALL.solver(2).reconstructed.ssim; +results(noise_ind,im_num).ssim.rlsdla=SMALL.solver(3).reconstructed.ssim; + +results(noise_ind,im_num).time.ksvd=SMALL.solver(1).time+SMALL.DL(1).time; +results(noise_ind,im_num).time.rlsdla.time=SMALL.solver(3).time+SMALL.DL(3).time; +clear SMALL; +end +end +% save results.mat results
--- a/examples/ALPS solvers tests/SMALL_solver_test_ALPS.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/ALPS solvers tests/SMALL_solver_test_ALPS.m Thu Nov 17 11:22:17 2011 +0000 @@ -88,7 +88,7 @@ % SMALL Conjugate Gradient test SMALL.solver(i)=SMALL_init_solver; SMALL.solver(i).toolbox='SMALL'; -SMALL.solver(i).name='SMALL_cgp'; +SMALL.solver(i).name='SMALL_pcgp'; % In the following string all parameters except matrix, measurement vector % and size of solution need to be specified. If you are not sure which
--- a/examples/Automatic Music Transcription/SMALL_AMT_DL_test.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Automatic Music Transcription/SMALL_AMT_DL_test.m Thu Nov 17 11:22:17 2011 +0000 @@ -31,7 +31,7 @@ % Defining Automatic Transcription of Piano tune as Dictionary Learning % Problem -SMALL.Problem = generateAMT_Learning_Problem(); +SMALL.Problem = generateAMTProblem(); %% % Use KSVD Dictionary Learning Algorithm to Learn 88 notes (defined in @@ -67,7 +67,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) SMALL_midiGenerate(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) AMT_reconstruct(x, SMALL.Problem); %% % Initialising solver structure @@ -151,7 +151,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(2).D; -SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem); +SMALL.Problem.reconstruct=@(x) AMT_reconstruct(x, SMALL.Problem); %% % Initialising solver structure
--- a/examples/Automatic Music Transcription/SMALL_AMT_KSVD_Err_test.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Automatic Music Transcription/SMALL_AMT_KSVD_Err_test.m Thu Nov 17 11:22:17 2011 +0000 @@ -33,7 +33,7 @@ % Defining Automatic Transcription of Piano tune as Dictionary Learning % Problem -SMALL.Problem = generateAMT_Learning_Problem(); +SMALL.Problem = generateAMTProblem(); TPmax=0; for i=1:5 %% @@ -76,7 +76,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(i).D; - SMALL.Problem.reconstruct = @(x) SMALL_midiGenerate(x, SMALL.Problem); + SMALL.Problem.reconstruct = @(x) AMT_reconstruct(x, SMALL.Problem); %% % Initialising solver structure
--- a/examples/Automatic Music Transcription/SMALL_AMT_KSVD_Sparsity_test.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Automatic Music Transcription/SMALL_AMT_KSVD_Sparsity_test.m Thu Nov 17 11:22:17 2011 +0000 @@ -33,7 +33,7 @@ % Defining Automatic Transcription of Piano tune as Dictionary Learning % Problem -SMALL.Problem = generateAMT_Learning_Problem(); +SMALL.Problem = generateAMTProblem(); TPmax=0; @@ -73,7 +73,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(i).D; - SMALL.Problem.reconstruct = @(x) SMALL_midiGenerate(x, SMALL.Problem); + SMALL.Problem.reconstruct = @(x) AMT_reconstruct(x, SMALL.Problem); %% % Initialising solver structure
--- a/examples/Automatic Music Transcription/SMALL_AMT_SPAMS_test.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Automatic Music Transcription/SMALL_AMT_SPAMS_test.m Thu Nov 17 11:22:17 2011 +0000 @@ -33,7 +33,7 @@ % Defining Automatic Transcription of Piano tune as Dictionary Learning % Problem -SMALL.Problem = generateAMT_Learning_Problem(); +SMALL.Problem = generateAMTProblem(); TPmax=0; %% for i=1:10 @@ -77,7 +77,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(i).D; - SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem); + SMALL.Problem.reconstruct=@(x) AMT_reconstruct(x, SMALL.Problem); %%
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsRLSDLA.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsRLSDLA.m Thu Nov 17 11:22:17 2011 +0000 @@ -99,7 +99,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); %% % Initialising solver structure @@ -140,7 +140,7 @@ % Setting up reconstruction function SparseDict=0; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem, SparseDict); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem, SparseDict); % Initialising solver structure % Setting solver structure fields (toolbox, name, param, solution, @@ -217,7 +217,7 @@ % reconstructed and time) to zero values SMALL.Problem.A = SMALL.DL(3).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); SMALL.solver(3)=SMALL_init_solver;
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsRLSDLAvsTwoStepMOD.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsRLSDLAvsTwoStepMOD.m Thu Nov 17 11:22:17 2011 +0000 @@ -9,10 +9,7 @@ % - KSVD - M. Elad, R. Rubinstein, and M. Zibulevsky, "Efficient % Implementation of the K-SVD Algorithm using Batch Orthogonal % Matching Pursuit", Technical Report - CS, Technion, April 2008. -% - RLS-DLA - Skretting, K.; Engan, K.; , "Recursive Least Squares -% Dictionary Learning Algorithm," Signal Processing, IEEE Transactions on, -% vol.58, no.4, pp.2121-2130, April 2010 -% + % Centre for Digital Music, Queen Mary, University of London. @@ -102,7 +99,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); %% % Initialising solver structure @@ -183,7 +180,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(2).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); % Denoising the image - find the sparse solution in the learned % dictionary for all patches in the image and the end it uses @@ -247,7 +244,7 @@ % reconstructed and time) to zero values SMALL.Problem.A = SMALL.DL(3).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); SMALL.solver(3)=SMALL_init_solver;
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsSPAMS.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsSPAMS.m Thu Nov 17 11:22:17 2011 +0000 @@ -97,7 +97,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); %% % Initialising solver structure @@ -175,7 +175,7 @@ % Setting up reconstruction function SparseDict=1; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem, SparseDict); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem, SparseDict); % Initialising solver structure % Setting solver structure fields (toolbox, name, param, solution, @@ -237,7 +237,7 @@ % Setting up reconstruction function -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); % Initialising solver structure % Setting solver structure fields (toolbox, name, param, solution,
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsTwoStepKSVD.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsTwoStepKSVD.m Thu Nov 17 11:22:17 2011 +0000 @@ -103,7 +103,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); %% % Initialising solver structure @@ -182,7 +182,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(2).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); % Denoising the image - find the sparse solution in the learned % dictionary for all patches in the image and the end it uses
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_SPAMS_lambda.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_SPAMS_lambda.m Thu Nov 17 11:22:17 2011 +0000 @@ -90,7 +90,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); %% % Initialising solver structure
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_Training_size.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_Training_size.m Thu Nov 17 11:22:17 2011 +0000 @@ -100,7 +100,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; - SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); + SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); %% % Initialising solver structure @@ -167,7 +167,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(2).D; - SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); + SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); %% % Initialising solver structure
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_TwoStep_KSVD_MOD_OLS_Mailhe.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_TwoStep_KSVD_MOD_OLS_Mailhe.m Thu Nov 17 11:22:17 2011 +0000 @@ -111,7 +111,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); % Denoising the image - find the sparse solution in the learned % dictionary for all patches in the image and the end it uses @@ -170,7 +170,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(2).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); % Denoising the image - find the sparse solution in the learned % dictionary for all patches in the image and the end it uses @@ -230,7 +230,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(3).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); % Denoising the image - find the sparse solution in the learned % dictionary for all patches in the image and the end it uses @@ -290,7 +290,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(4).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); % Denoising the image - find the sparse solution in the learned % dictionary for all patches in the image and the end it uses
--- a/examples/MajorizationMinimization tests/SMALL_AMT_DL_test_KSVD_MM.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/MajorizationMinimization tests/SMALL_AMT_DL_test_KSVD_MM.m Thu Nov 17 11:22:17 2011 +0000 @@ -38,7 +38,7 @@ % Defining Automatic Transcription of Piano tune as Dictionary Learning % Problem -SMALL.Problem = generateAMT_Learning_Problem('',2048,0.75); +SMALL.Problem = generateAMTProblem('',2048,0.75); %% % Use KSVD Dictionary Learning Algorithm to Learn 88 notes (defined in @@ -74,7 +74,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) SMALL_midiGenerate(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) AMT_reconstruct(x, SMALL.Problem); %% % Initialising solver structure @@ -89,7 +89,7 @@ % Defining the parameters needed for sparse representation SMALL.solver(1).toolbox='SMALL'; -SMALL.solver(1).name='SMALL_cgp'; +SMALL.solver(1).name='SMALL_pcgp'; % Here we use mexLasso mode=2, with lambda=2, lambda2=0 and positivity % constrain (type 'help mexLasso' for more information about modes): @@ -216,7 +216,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(2).D; -SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem); +SMALL.Problem.reconstruct=@(x) AMT_reconstruct(x, SMALL.Problem); % Call SMALL_soolve to represent the signal in the given dictionary.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/MajorizationMinimization tests/SMALL_AudioDenoise_DL_test_KSVDvsSPAMS.m Thu Nov 17 11:22:17 2011 +0000 @@ -0,0 +1,128 @@ +%% DICTIONARY LEARNING FOR AUDIO DENOISING +% This file contains an example of how SMALLbox can be used to test different +% dictionary learning techniques in Audio Denoising problem. +% It calls generateAudioDenoiseProblem that will let you to choose audio file, +% add noise and use noisy audio to generate training set for dictionary +% learning. +% +% +% Centre for Digital Music, Queen Mary, University of London. +% This file copyright 2011 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. +% +%% + +clear; + +% Defining Audio Denoising Problem as Dictionary Learning +% Problem + +SMALL.Problem = generateAudioDenoiseProblem('male01_8kHz',0.1,512,1/128,'','','',4); + +%% +% Initialising solver structure +% Setting solver structure fields (toolbox, name, param, solution, +% reconstructed and time) to zero values + +SMALL.solver(1)=SMALL_init_solver('MMbox', 'mm1', '', 1); + +% Defining the parameters needed for image denoising + +SMALL.solver(1).param=struct(... + 'lambda', 0.2,... + 'epsilon', 3*10^-4,... + 'iternum',10); + +% Initialising Dictionary structure +% Setting Dictionary structure fields (toolbox, name, param, D and time) +% to zero values + +SMALL.DL(1)=SMALL_init_DL('MMbox', 'MM_cn', '', 1); + + +% Defining the parameters for MOD +% In this example we are learning 256 atoms in 20 iterations, so that +% every patch in the training set can be represented with target error in +% L2-norm (EData) +% Type help ksvd in MATLAB prompt for more options. + + +SMALL.DL(1).param=struct(... + 'solver', SMALL.solver(1),... + 'initdict', SMALL.Problem.initdict,... + 'dictsize', SMALL.Problem.p,... + 'iternum', 20,... + 'iterDictUpdate', 10,... + 'epsDictUpdate', 10^-7,... + 'cvset',0,... + 'show_dict', 0); + +% Learn the dictionary + +SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1)); + +% Set SMALL.Problem.A dictionary +% (backward compatiblity with SPARCO: solver structure communicate +% only with Problem structure, ie no direct communication between DL and +% solver structures) + +SMALL.Problem.A = SMALL.DL(1).D; +SMALL.Problem.reconstruct = @(x) AudioDenoise_reconstruct(x, SMALL.Problem); +% Denoising the image - find the sparse solution in the learned +% dictionary for all patches in the image and the end it uses +% reconstruction function to reconstruct the patches and put them into a +% denoised image + +SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1)); + +%% +%% +% % sparse coding using SPAMS online dictionary learning +% + +SMALL.DL(2)=SMALL_init_DL(); +SMALL.DL(2).toolbox = 'SPAMS'; +SMALL.DL(2).name = 'mexTrainDL'; +SMALL.DL(2).param=struct('D', SMALL.Problem.initdict, 'K', SMALL.Problem.p, 'lambda', 0.2, 'iter', 200, 'mode', 3, 'modeD', 0); + + +SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); + +% Defining Reconstruction function + +SMALL.Problem.A = SMALL.DL(2).D; + + +%% +% Initialising solver structure +% Setting toolbox, name, param, solution, reconstructed and time to zero values + +SMALL.solver(2)=SMALL_init_solver; + +% Defining the parameters needed for sparse representation + +SMALL.solver(2).toolbox='ompbox'; +SMALL.solver(2).name='omp2'; +SMALL.solver(2).param=struct(... + 'epsilon',0.2,... + 'maxatoms', 128); +% Represent Training set in the learned dictionary + +SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); + + + + +%% +% Plot results and save midi files + +% show results % + + +SMALL_AudioDeNoiseResult(SMALL); + \ No newline at end of file
--- a/examples/MajorizationMinimization tests/SMALL_ImgDenoise_DL_test_KSVDvsMajorizationMinimization.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/MajorizationMinimization tests/SMALL_ImgDenoise_DL_test_KSVDvsMajorizationMinimization.m Thu Nov 17 11:22:17 2011 +0000 @@ -103,7 +103,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(1).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); %% % Initialising solver structure @@ -184,7 +184,7 @@ % solver structures) SMALL.Problem.A = SMALL.DL(2).D; -SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); +SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); % Denoising the image - find the sparse solution in the learned % dictionary for all patches in the image and the end it uses
--- a/examples/Pierre Villars/Pierre_Villars_Example.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/Pierre Villars/Pierre_Villars_Example.m Thu Nov 17 11:22:17 2011 +0000 @@ -23,7 +23,7 @@ % Defining the Problem structure -SMALL.Problem = generatePierre_Problem(); +SMALL.Problem = generatePierreProblem(); % Show original image and image that is used as a dictionary figure('Name', 'Original and Dictionary Image');
--- a/examples/SMALL_solver_test.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/SMALL_solver_test.m Thu Nov 17 11:22:17 2011 +0000 @@ -81,7 +81,7 @@ % SMALL Conjugate Gradient test SMALL.solver(i)=SMALL_init_solver; SMALL.solver(i).toolbox='SMALL'; -SMALL.solver(i).name='SMALL_cgp'; +SMALL.solver(i).name='SMALL_pcgp'; % In the following string all parameters except matrix, measurement vector % and size of solution need to be specified. If you are not sure which
--- a/examples/SMALL_solver_test_Audio.m Thu Nov 17 11:18:25 2011 +0000 +++ b/examples/SMALL_solver_test_Audio.m Thu Nov 17 11:22:17 2011 +0000 @@ -61,7 +61,7 @@ SMALL.solver(i)=SMALL_init_solver; SMALL.solver(i).toolbox='SMALL'; -SMALL.solver(i).name='SMALL_cgp'; +SMALL.solver(i).name='SMALL_pcgp'; % In the following string all parameters except matrix, measurement vector % and size of solution need to be specified. If you are not sure which
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/solvers/SMALL_pcgp.m Thu Nov 17 11:22:17 2011 +0000 @@ -0,0 +1,113 @@ +function [A, resF]=SMALL_pcgp(Dict,X, m, maxNumCoef, errorGoal, varargin) +%% Partial Conjugate Gradient Pursuit Multiple vectors sparse representation +% +% Sparse coding of a group of signals based on a given +% dictionary and specified number of atoms to use. +% input arguments: Dict - the dictionary +% X - the signals to represent +% m - number of atoms in Dictionary +% errorGoal - the maximal allowed representation error for +% each signal. +% +% optional: if Dict is function handle then Transpose Dictionary +% handle needs to be specified. +% +% output arguments: A - sparse coefficient matrix. + +% +% Centre for Digital Music, Queen Mary, University of London. +% This file copyright 2009 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. +% +%% + +% This Dictionary check is based on Thomas Blumensath work in sparsify 0_4 greedy solvers +if isa(Dict,'float') + D =@(z) Dict*z; + Dt =@(z) Dict'*z; +elseif isobject(Dict) + D =@(z) Dict*z; + Dt =@(z) Dict'*z; +elseif isa(Dict,'function_handle') + try + DictT=varargin{1}; + if isa(DictT,'function_handle'); + D=Dict; + Dt=DictT; + else + error('If Dictionary is a function handle,Transpose Dictionary also needs to be a function handle. '); + end + catch + error('If Dictionary is a function handle, Transpose Dictionary needs to be specified. Exiting.'); + end +else + error('Dictionary is of unsupported type. Use explicit matrix, function_handle or object. Exiting.'); +end +%% +%positivity=1; +[n,P]=size(X); + + + +A = sparse(m,size(X,2)); + +for k=1:1:P, + + x = X(:,k); + residual = x; + indx =[]; + j=0; + + + currResNorm = residual'*residual/n; + errGoal=errorGoal*currResNorm; + a = zeros(m,1); + p = zeros(m,1); + + while j < maxNumCoef, + + j = j+1; + dir=Dt(residual); + if exist('positivity','var')&&(positivity==1) + [tmp__, pos]=max(dir); + else + [tmp__, pos]=max(abs(dir)); + end + indx(j)=pos; + + p(indx)=dir(indx); + Dp=D(p); + pDDp=Dp'*Dp; + + if (j==1) + beta=0; + else + beta=-Dp'*residual/pDDp; + end + + alfa=residual'*Dp/pDDp; + a=a+alfa*p; + p(indx)=dir(indx)+beta*p(indx); + + residual=residual-alfa*Dp; + + currResNorm = residual'*residual/n; + if currResNorm<errGoal + fprintf('\nFound exact representation! \n'); + break; + end + end; + if (~isempty(indx)) + resF(k)=currResNorm; + A(indx,k)=a(indx); + end +end; +return; + + +
--- a/util/SMALL_AudioDeNoiseResult.m Thu Nov 17 11:18:25 2011 +0000 +++ b/util/SMALL_AudioDeNoiseResult.m Thu Nov 17 11:22:17 2011 +0000 @@ -2,7 +2,7 @@ %% Plots the results of Audio denoising experiment - underconstruction % Centre for Digital Music, Queen Mary, University of London. -% This file copyright 2009 Ivan Damnjanovic. +% This file copyright 2011 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 @@ -13,7 +13,7 @@ fMain=figure('Name', sprintf('File %s (training set size- %d, sigma - %d)',SMALL.Problem.name, SMALL.Problem.n, SMALL.Problem.sigma)); m=size(SMALL.solver,2); -maxval=SMALL.Problem.maxval; +maxval=max(SMALL.Problem.Original); au=SMALL.Problem.Original; aunoise=SMALL.Problem.Noisy; @@ -25,7 +25,7 @@ for i=1:m params=SMALL.solver(i).param; - sWav=subplot(2, m, m+i, 'Parent', fMain); plot(SMALL.solver(i).reconstructed.Image/maxval, 'Parent', sWav); + sWav=subplot(2, m, m+i, 'Parent', fMain); plot(SMALL.solver(i).reconstructed.audio/maxval, 'Parent', sWav); title(sprintf('%s Denoised audio, PSNR: %.2fdB', SMALL.DL(i).name, SMALL.solver(i).reconstructed.psnr),'Parent', sWav ); if strcmpi(SMALL.DL(i).name,'ksvds') D = kron(SMALL.Problem.basedict{2},SMALL.Problem.basedict{1})*SMALL.DL(i).D;
--- a/util/SMALL_solve.m Thu Nov 17 11:18:25 2011 +0000 +++ b/util/SMALL_solve.m Thu Nov 17 11:22:17 2011 +0000 @@ -1,5 +1,5 @@ function solver = SMALL_solve(Problem, solver) -%% SMALL sparse solver +%% SMALL sparse solver caller function % % Function gets as input SMALL structure that contains SPARCO problem to % be solved, name of the toolbox and solver, and parameters file for @@ -88,7 +88,7 @@ [y, numiter, time, y_path] = wrapper_ALPS_toolbox(b, A, solver.param); elseif (strcmpi(solver.toolbox, 'MMbox')) if ~isa(Problem.A,'float') - % ALPS does not accept implicit dictionary definition + % MMbox does not accept implicit dictionary definition A = opToMatrix(Problem.A, 1); end