Matlab指纹方向场方向图程序

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

        

        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值