ivan@130: function data=generatePierre_Problem(src, trg, blocksize, dictsize); ivan@130: %% Generate Pierre Villars Problem ivan@130: % ivan@130: % Pierre_Problem is a part of the SMALLbox and generates the problem ivan@130: % suggested by Professor Pierre Vandergheynst on the SMALL meeting in ivan@130: % Villars. ivan@130: % The function takes as an input: ivan@130: % - src - source image matrix (if not present function promts user for ivan@130: % an image file) , ivan@130: % - trg - target image matrix (if not present function promts user for ivan@130: % an image file) , ivan@130: % - blocksize - block (patch) vertical/horizontal dimension (default 8), ivan@130: % - dictsize - dictionary size (default - all patches from target ivan@130: % image). ivan@130: % ivan@130: % The output of the function is stucture with following fields: ivan@130: % - srcname - source image name, ivan@130: % - imageSrc - source image matrix, ivan@130: % - trgname - target image name, ivan@130: % - imageTrg - Target image matrix, ivan@130: % - A - dictonary with patches from the source image, ivan@130: % - b - measurement matrix (i.e. patches from target image to be ivan@130: % represented in dictionary A, ivan@130: % - m - size of patches (default 25), ivan@130: % - n - number of patches to be represented, ivan@130: % - p - dictionary size, ivan@130: % - blocksize - block size (default [5 5]), ivan@130: % - maxval - maximum value (default - 255) ivan@130: % - sparse - if 1 SMALL_solve will keep solution matrix in sparse form, ivan@130: % due to memory constrains. ivan@130: ivan@130: % ivan@130: % Centre for Digital Music, Queen Mary, University of London. ivan@130: % This file copyright 2010 Ivan Damnjanovic. ivan@130: % ivan@130: % This program is free software; you can redistribute it and/or ivan@130: % modify it under the terms of the GNU General Public License as ivan@130: % published by the Free Software Foundation; either version 2 of the ivan@130: % License, or (at your option) any later version. See the file ivan@130: % COPYING included with this distribution for more information. ivan@130: %% prompt user for images %% ivan@130: ivan@130: % ask for source file name ivan@130: ivan@130: TMPpath=pwd; ivan@130: FS=filesep; ivan@130: if ~ exist( 'src', 'var' ) || isempty(src) luis@186: [pathstr1, name, ext] = fileparts(which('SMALLboxSetup.m')); ivan@130: cd([pathstr1,FS,'data',FS,'images']); ivan@130: [filename,pathname] = uigetfile({'*.png;'},'Select a source image'); luis@186: [pathstr, name, ext] = fileparts(filename); ivan@130: data.srcname=name; ivan@130: src = imread(filename); ivan@130: src = double(src); ivan@130: end; ivan@130: ivan@130: % ask for target file name ivan@130: ivan@130: if ~ exist( 'trg', 'var' ) || isempty(trg) ivan@130: [filename,pathname] = uigetfile({'*.png;'},'Select a target image'); luis@186: [pathstr, name, ext] = fileparts(filename); ivan@130: data.trgname=name; ivan@130: trg = imread(filename); ivan@130: trg = double(trg); ivan@130: end; ivan@130: cd(TMPpath); ivan@130: ivan@130: %% set parameters %% ivan@130: ivan@130: maxval = 255; ivan@130: if ~ exist( 'blocksize', 'var' ) || isempty(blocksize),blocksize = 5;end ivan@130: ivan@130: if ~ exist( 'dictsize', 'var' ) || isempty(dictsize), ivan@130: dictsize = (size(src,1)-blocksize+1)*(size(src,2)-blocksize+1); ivan@130: patch_idx=1:dictsize; ivan@130: else ivan@130: num_blocks_src=(size(src,1)-blocksize+1)*(size(src,2)-blocksize+1); ivan@130: patch_idx=1:floor(num_blocks_src/dictsize):dictsize*floor(num_blocks_src/dictsize); ivan@130: end ivan@130: ivan@130: p = ndims(src); ivan@130: if (p==2 && any(size(src)==1) && length(blocksize)==1) ivan@130: p = 1; ivan@130: end ivan@130: ivan@130: ivan@130: % blocksize % ivan@130: if (numel(blocksize)==1) ivan@130: blocksize = ones(1,p)*blocksize; ivan@130: end ivan@130: %% ivan@130: %% create dictionary data %% ivan@130: ivan@130: S=im2colstep(src,blocksize); ivan@130: ivan@130: for j= 1:size(S,2) ivan@130: S(:,j)=S(:,j)./norm(S(:,j)); ivan@130: end ivan@130: ivan@130: %% create measurement matrix %% ivan@130: ivan@130: T=im2colstep(trg,blocksize, blocksize); ivan@130: ivan@130: %% output structure %% ivan@130: ivan@130: data.imageSrc = src; ivan@130: data.imageTrg = trg; ivan@130: data.A = S(:,patch_idx); ivan@130: data.b = T; ivan@130: data.m = size(T,1); ivan@130: data.n = size(T,2); ivan@130: data.p = size(data.A,2); ivan@130: data.blocksize=blocksize; ivan@130: data.maxval=maxval; ivan@130: ivan@130: % keep coefficients matrix in sparse form and do not convert it to full. ivan@130: % getting around out of memory problem when converting big matrix from ivan@130: % sparse to full... (check SMALL_solve function) ivan@130: data.sparse=1; ivan@130: ivan@130: