annotate util/sparco utils/genPDF.m @ 99:e22f8494c5ff

Merge
author Mark Plumbley <mark.plumbley@eecs.qmul.ac.uk>
date Tue, 12 Apr 2011 14:33:24 +0100
parents 62f20b91d870
children
rev   line source
ivan@77 1 function [pdf,val] = genPDF(imSize,p,pctg,distType,radius,disp)
ivan@77 2
ivan@77 3 %[pdf,val] = genPDF(imSize,p,pctg [,distType,radius,disp])
ivan@77 4 %
ivan@77 5 % generates a pdf for a 1d or 2d random sampling pattern
ivan@77 6 % with polynomial variable density sampling
ivan@77 7 %
ivan@77 8 % Input:
ivan@77 9 % imSize - size of matrix or vector
ivan@77 10 % p - power of polynomial
ivan@77 11 % pctg - partial sampling factor e.g. 0.5 for half
ivan@77 12 % distType - 1 or 2 for L1 or L2 distance measure
ivan@77 13 % radius - radius of fully sampled center
ivan@77 14 % disp - display output
ivan@77 15 %
ivan@77 16 % Output:
ivan@77 17 % pdf - the pdf
ivan@77 18 % val - min sampling density
ivan@77 19 %
ivan@77 20 %
ivan@77 21 % Example:
ivan@77 22 % [pdf,val] = genPDF([128,128],2,0.5,2,0,1);
ivan@77 23 %
ivan@77 24 % (c) Michael Lustig 2007
ivan@77 25
ivan@77 26 % This file is used with the kind permission of Michael Lustig
ivan@77 27 % (mlustig@stanford.edu), and originally appeared in the
ivan@77 28 % SparseMRI toolbox, http://www.stanford.edu/~mlustig/ .
ivan@77 29 %
ivan@77 30 % $Id: genPDF.m 1040 2008-06-26 20:29:02Z ewout78 $
ivan@77 31
ivan@77 32
ivan@77 33 if nargin < 4
ivan@77 34 distType = 2;
ivan@77 35 end
ivan@77 36
ivan@77 37 if nargin < 5
ivan@77 38 radius = 0;
ivan@77 39 end
ivan@77 40
ivan@77 41 if nargin < 6
ivan@77 42 disp = 0;
ivan@77 43 end
ivan@77 44
ivan@77 45
ivan@77 46 minval=0;
ivan@77 47 maxval=1;
ivan@77 48 val = 0.5;
ivan@77 49
ivan@77 50 if length(imSize)==1
ivan@77 51 imSize = [imSize,1];
ivan@77 52 end
ivan@77 53
ivan@77 54 sx = imSize(1);
ivan@77 55 sy = imSize(2);
ivan@77 56 PCTG = floor(pctg*sx*sy);
ivan@77 57
ivan@77 58
ivan@77 59 if sum(imSize==1)==0 % 2D
ivan@77 60 [x,y] = meshgrid(linspace(-1,1,sy),linspace(-1,1,sx));
ivan@77 61 switch distType
ivan@77 62 case 1
ivan@77 63 r = max(abs(x),abs(y));
ivan@77 64 otherwise
ivan@77 65 r = sqrt(x.^2+y.^2);
ivan@77 66 r = r/max(abs(r(:)));
ivan@77 67 end
ivan@77 68
ivan@77 69 else %1d
ivan@77 70 r = abs(linspace(-1,1,max(sx,sy)));
ivan@77 71 end
ivan@77 72
ivan@77 73
ivan@77 74
ivan@77 75
ivan@77 76 idx = find(r<radius);
ivan@77 77
ivan@77 78 pdf = (1-r).^p; pdf(idx) = 1;
ivan@77 79 if floor(sum(pdf(:))) > PCTG
ivan@77 80 error('infeasible without undersampling dc, increase p');
ivan@77 81 end
ivan@77 82
ivan@77 83 % begin bisection
ivan@77 84 while(1)
ivan@77 85 val = minval/2 + maxval/2;
ivan@77 86 pdf = (1-r).^p + val; pdf(find(pdf>1)) = 1; pdf(idx)=1;
ivan@77 87 N = floor(sum(pdf(:)));
ivan@77 88 if N > PCTG % infeasible
ivan@77 89 maxval=val;
ivan@77 90 end
ivan@77 91 if N < PCTG % feasible, but not optimal
ivan@77 92 minval=val;
ivan@77 93 end
ivan@77 94 if N==PCTG % optimal
ivan@77 95 break;
ivan@77 96 end
ivan@77 97 end
ivan@77 98
ivan@77 99 if disp
ivan@77 100 figure,
ivan@77 101 subplot(211), imshow(pdf)
ivan@77 102 if sum(imSize==1)==0
ivan@77 103 subplot(212), plot(pdf(end/2+1,:));
ivan@77 104 else
ivan@77 105 subplot(212), plot(pdf);
ivan@77 106 end
ivan@77 107 end
ivan@77 108
ivan@77 109
ivan@77 110
ivan@77 111
ivan@77 112
ivan@77 113