function F=doflatten(img, dg, ind) %DOFLATTEN Flatten the image % % Copyright (c) 1995 by Claudio Rivetti and Mark Young % claudio@alice.uoregon.edu, mark@alice.uoregon.edu % global Handlefig f=watchon; im=zeros(size(img)); im(ind)=im(ind)*NaN; rows=size(img,1); cols=size(img,2); F=zeros(rows, cols); x=1:cols; for i=1:rows y=im(i,x); indx=find(~isnan(y)); xx=x(indx); c=polyfit(xx,img(i,indx), dg); F(i,x)=img(i,x) - polyval(c,x); progressbar(i/rows, 'Flattening image'); end watchoff(f); return;