annotate Problems/private/genPDF.m @ 61:42fcbcfca132

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