这个算法的原理是来源于南京邮电大学 张伟的《鱼眼图像校正算法研究》这幅是此算法得到的有效区域的提取图这幅是原图 未扫描之前的
function B=everyline_everyrow_sweep(A,T)
% A is a yuyan picture and the function is meant to correct the picture by% the function of every line and every row sweeping.So picture B is the
% result we get.T is yuzhi.
[m,n,k]=size(A);
for i=1:m
I(i,1,:)=0.59*A(i,1,1)+0.11*A(i,1,2)+0.3*A(i,1,3);
Imax=I(i,1,:);
Imin=I(i,1,:);
for j=2:n
I(i,j,:)=0.59*A(i,j,1)+0.11*A(i,j,2)+0.3*A(i,j,3);
if(I(i,j,:)>Imax)
Imax=I(i,j,:);
elseif(I(i,j,:)<Imin)
Imin=I(i,j,:);
end
end
if(Imax-Imin>=T)
top=i;
break;
end
end
for i=m:-1:1
I(i,1,:)=0.59*A(i,1,1)+0.11*A(i,1,2)+0.3*A(i,1,3);
Imax=I(i,1,:);
Imin=I(i,1,:);
for j=2:n
I(i,j,:)=0.59*A(i,j,1)+0.11*A(i,j,2)+0.3*A(i,j,3);
if(I(i,j,:)>Imax)
Imax=I(i,j,:);
elseif(I(i,j,:)<Imin)
Imin=I(i,j,:);
end
end
if(Imax-Imin>=T)
bottom=i;
break;
end
end
for j=1:n
I(1,j,:)=0.59*A(1,j,1)+0.11*A(1,j,2)+0.3*A(1,j,3);
Imax=I(1,j,:);
Imin=I(1,j,:);
for i=1:m
I(i,j,:)=0.59*A(i,j,1)+0.11*A(i,j,2)+0.3*A(i,j,3);
if(I(i,j,:)>Imax)
Imax=I(i,j,:);
elseif(I(i,j,:)<Imin)
Imin=I(i,j,:);
end
end
if(Imax-Imin>=T)
left=j;
break;
end
end
for j=n:-1:1
I(1,j,:)=0.59*A(1,j,1)+0.11*A(1,j,2)+0.3*A(1,j,3);
Imax=I(1,j,:);
Imin=I(1,j,:);
for i=1:m
I(i,j,:)=0.59*A(i,j,1)+0.11*A(i,j,2)+0.3*A(i,j,3);
if(I(i,j,:)>Imax)
Imax=I(i,j,:);
elseif(I(i,j,:)<Imin)
Imin=I(i,j,:);
end
end
if(Imax-Imin>=T)
right=j;
break;
end
end
x=(left+right)/2;
y=(top+bottom)/2;
R=max((right-left)/2,(bottom-top)/2);
B=imcrop(A,[left,top,2*R,2*R]);