x=d; m=zeros(1,N); l=zeros(1,N); m(1)=alpha(1); for i=2:N l(i)=gama(i)/m(i-1); m(i)=alpha(i)-l(i)*beta(i-1); end y=zeros(1,N); y(1)=d(1); for i=2:N y(i)=d(i)-l(i)*y(i-1); end
x=zeros(1,N); x(N)=y(N)/m(N); for i=N-1:-1:1 x(i)=(y(i)-beta(i)*x(i+1))/m(i); end
if (hks>1) xL=mean(I(:,1:hks)‘)‘; xR=mean(I(:,Nx-hks+1:Nx)‘)‘; else xL=I(:,1); xR=I(:,Nx); end eI=[xL*ones(1,hks) I xR*ones(1,hks)]; if (hks>1) xU=mean(eI(1:hks,:)); xD=mean(eI(Ny-hks+1:Ny,:)); else xU=eI(1,:); xD=eI(Ny,:); end eI=[ones(hks,1)*xU; eI; ones(hks,1)*xD]; Ig=conv2(eI,flt,‘valid‘); end
%用以控制迭代次数 %iterations = 2; %for times = 1:iterations I_temp=gauss(Img,3,1); Ix = 0.5*(I_temp(:,[2:ncol,ncol])-I_temp(:,[1,1:ncol-1])); Iy = 0.5*(I_temp([2:nrow,nrow],:)-I_temp([1,1:nrow-1],:)); K = 10 grad=Ix.^2+Iy.^2; g=1./(1+grad/K*K); %边缘压迫因子
% 使用Thomas算法逐行求解u1 for i=1:nrow beta(1)=-0.5*timestep*(g(i,2)+g(i,1)); alpha(1)=1-beta(1); for j=2:ncol-1 beta(j)=-0.5*timestep*(g(i,j+1)+g(i,j)); gama(j)=-0.5*timestep*(g(i,j-1)+g(i,j)); alpha(j)=1-beta(j)-gama(j); end gama(ncol)=-0.5*timestep*(g(i,ncol)+g(i,ncol-1)); alpha(ncol)=1- gama(ncol); u1(i,:)=Thomas(ncol,alpha,beta,gama,Img(i,:)); end
% 使用Thomas算法逐列求解u2 for j=1:ncol beta(1)=-0.5*timestep*(g(2,j)+g(1,j)); alpha(1)=1-beta(1); for i=2:nrow-1 beta(j)=-0.5*timestep*(g(i+1,j)+g(i,j)); gama(j)=-0.5*timestep*(g(i-1,j)+g(i,j)); alpha(j)=1-beta(j)-gama(j); end gama(nrow)=-0.5*timestep*(g(nrow,j)+g(nrow-1,j)); alpha(nrow)=1- gama(nrow); u2(:,j)=Thomas(nrow,alpha,beta,gama,Img(:,j)); end Img=0.5*(u1+u2); % 显示处理结果 imshow(uint8(Img)); %end