【三维LK光流】基于Lucas Kanade三维光流提取算法的MATLAB仿真

1.软件版本

MATLAB2021a

2.部分核心代码

function [ux,uy,uz]=LK3D( image1, image2, r )


%  Default parameter
if nargin==2
    r=2;
end

[height,width,depth]=size(image1); 
image1=im2double(image1);
image2=im2double(image2);

% Initializing flow vectors
ux=zeros(size(image1)); uy=ux; uz=ux;

% Computing image derivatives
[Ix,Iy,Iz,It]=imageDerivatives3D(image1,image2);

for i=(r+1):(height-r)
    for j=(r+1):(width-r)
        for k=(r+1):(depth-r)
        
        blockofIx=Ix(i-r:i+r,j-r:j+r,k-r:k+r);
        blockofIy=Iy(i-r:i+r,j-r:j+r,k-r:k+r);
        blockofIz=Iz(i-r:i+r,j-r:j+r,k-r:k+r);
        blockofIt=It(i-r:i+r,j-r:j+r,k-r:k+r);

               
        A=zeros(3,3);
        B=zeros(3,1);
        
        A(1,1)=sum(sum(sum(blockofIx.^2)));
        A(1,2)=sum(sum(sum(blockofIx.*blockofIy)));
        A(1,3)=sum(sum(sum(blockofIx.*blockofIz)));
        
        A(2,1)=sum(sum(sum(blockofIy.*blockofIx)));
        A(2,2)=sum(sum(sum(blockofIy.^2)));
        A(2,3)=sum(sum(sum(blockofIy.*blockofIz)));

        A(3,1)=sum(sum(sum(blockofIz.*blockofIx)));
        A(3,2)=sum(sum(sum(blockofIz.*blockofIy)));
        A(3,3)=sum(sum(sum(blockofIz.^2)));
       
        B(1,1)=sum(sum(sum(blockofIx.*blockofIt)));
        B(2,1)=sum(sum(sum(blockofIy.*blockofIt)));
        B(3,1)=sum(sum(sum(blockofIz.*blockofIt)));
        
        invofA=pinv(A);
        
        V=invofA*(-B);
        ux(i,j,k)=V(1,1);
        uy(i,j,k)=V(2,1);
        uz(i,j,k)=V(3,1);
        end
    end
end

end

3.操作步骤与仿真结论

【三维LK光流】基于Lucas Kanade三维光流提取算法的MATLAB仿真_第1张图片

4.参考文献

[1]谢红, 原博, 解武. LK光流法和三帧差分法的运动目标检测算法[J]. 应用科技, 2016, 43(3):6.

D231

你可能感兴趣的:(MATLAB,板块2:图像-特征提取处理,三维光流,LK光流)