% Mark D. Shattuck 3/29/2008 % Particle tracking demonstration % User Inputs D=12; % Initial Diameter Guess w=1.3; % Initial Width Guess Cutoff=5; % minimum peak intensity MinSep=5; % minimum separation between peaks hi=250; % hi and lo values come the image histogram lo=10; % hi/lo=typical pixel value outside/inside maxDwnr=10; % maximum number of calls to cidDw Newton solver. mindelD=.0001; % minimum change in D before stopping maxnr=5; % maximum number of calls to cidp2 Newton solver. mindelchi2=1; % minimum change in chi2 before stopping % setup for ideal particle ss=2*fix(D/2+4*w/2)-1; % size of ideal particle image os=(ss-1)/2; % (size-1)/2 of ideal particle image [xx yy]=ndgrid(-os:os,-os:os); % ideal particle image grid r=abs(xx+i*yy); % radial coordinate raw=imread('test.bmp'); % load image [Nx Ny]=size(raw); % image size ri=(hi-double(raw))/(hi-lo); % normalize image % find pixel accurate centers using chi-squared [Np px py]=findpeaks(1./chiimg(ri,ipf(r,D,w)),1,Cutoff,MinSep); % find maxima % Minimizing chi-squared for sub-pixel accuracy [cxy over]=pgrid(px-os,py-os,Nx,Ny,[1 Nx 1 Ny],Np,2*os+3,0); % create local grid centered on each particle and overlap matrix ci=ipf(cxy,D,w); % create calculated image di=ci-ri; % Calculate difference image chi2=sum(di(:).^2); % Calculate Chi-Squared fprintf('Chi-Squared=%f\n',chi2); chi2o=chi2;di0=di; % save for later % find best D and w nr=0; delD=1e99; while((abs(delD)>mindelD) && (nrmindelchi2) && (nr