function Fangxiangtu = zhiwen_fangxiangtu( Zhiwentuxiang )
%函数功能 计算指纹方向图
%函数参数 指纹图像 Zhiwentuxiang
%函数返回值 指纹方向图Fangxiangtu
SizeZhiwentuxiang = size( Zhiwentuxiang ) ;
Zhiwentuxiang = double( Zhiwentuxiang ) ;
W = 4; % 窗口大小 (2W+1)*(2W+1)
W = 4;
%Sobel算子
x_fangxiang = [-1 0 1;
-2 0 2;
-1 0 1];
y_fangxiang = [1 2 1;
0 0 0;
-1 -2 -1];
SizeZhiwentuxiang = size( Zhiwentuxiang );
Gx = zeros( SizeZhiwentuxiang );
Gy = zeros( SizeZhiwentuxiang );
Fangxiangtu = zeros( SizeZhiwentuxiang );
for i = 2 : SizeZhiwentuxiang( 1 , 1 ) - 1
for j = 2 : SizeZhiwentuxiang( 1, 2 ) - 1
Sum_x = 0;%j方向
Sum_y = 0;%i方向
for k = -1 : 1
for r = -1 : 1
Sum_x = Sum_x + x_fangxiang( k + 2 , r + 2 ) * Zhiwentuxiang( i + k , j + r );
Sum_y = Sum_y + y_fangxiang( k + 2 , r + 2 ) * Zhiwentuxiang( i + k , j + r );
end
end
Gx( i , j ) = Sum_x ;
Gy( i , j ) = Sum_y ;
end
end
for i = W+1 : SizeZhiwentuxiang( 1 , 1 ) - W
for j = W+1 : SizeZhiwentuxiang( 1, 2 ) - W
Vx = 0;
Vy = 0 ;
for io = -W : W
for jo = -W : W
Vy = Vy + 2 * Gx( i + io , j + jo ) * Gy( i + io , j + jo );
Vx = Vx + Gx( i + io , j + jo ).^2 - Gy( i + io , j + jo ).^2;
end
end
if Vx ~= 0
th = atan( Vy / Vx ) / 2 ;
Fangxiangtu( i , j ) = th ;
else
Fangxiangtu( i , j ) = pi / 2;
end
end
end