双目图像深度信息提取matlab仿真

发布时间 2023-05-21 23:52:22作者: 我爱C编程

1.算法仿真效果

matlab2022a仿真结果如下:

 

 

 

 

 

 

2.算法涉及理论知识概要

         深度学习的蓬勃发展得益于大规模有标注的数据驱动,有监督学习(supervised learning)推动深度模型向着性能越来越高的方向发展。但是,大量的标注数据往往需要付出巨大的人力成本,越来越多的研究开始关注如何在不获取数据标签的条件下提升模型的性能,也就是自监督学习(self-supervised learning/无监督学习(unsupervised learning)。

 

       对于立体匹配(stereo matching),或者双目深度估计,像LiDAR这样的设备是极其笨重且昂贵的,它所能收集的只是稀疏的深度信息,而我们需要的是密集的深度图(dense depth map);而基于结构光的设备往往只能在室内场景下进行深度信息标注,在室外场景下难以达到较高的标注质量。因此,自监督学习在立体匹配中得到越来越多的关注。本文主要梳理了近年来自监督学习在深度立体匹配中的应用方法,希望和大家一起探讨学习。

 

        常用的基于区域的局部匹配准则主要有图像序列中对应像素差的绝对值(SAD, Sum of Absolute Differences),图像序列中对应像素差的平方和(SSD, Sum of Squared Differences),图像的相关性(NCC, Normalized Cross Correlation)等.

 

     绝对误差和算法(Sum of Absolute Differences,简称SAD算法)。实际上,SAD算法与MAD算法思想几乎是完全一致,只是其相似度测量公式有一点改动(计算的是子图与模板图的L1距离),这里不再赘述。

 

 

 

3.MATLAB核心程序

 

WS  = uint16(windowsize);               % Set window size, must be uneven
WS2 = uint16( ( WS - 1 ) / 2 );         % Half window
D   = uint16(disparity)+1;              % number of disparities
 
heightL = uint16( size( imgleft, 1 ) );    heightR = uint16( size( imgright, 1 ) );
widthL  = uint16( size( imgleft, 2 ) );    widthR  = uint16( size( imgright, 2 ) );
if ( heightL ~= heightR  ||  widthL ~= widthR )
    error('Height and width of left and right image must be equal');
end
 
 
pcost = zeros( heightL, widthL, D, 'uint8' );
wcost = zeros( heightL, widthL, D, 'single' );
dmap  = zeros( heightL, widthL, 'uint8' );
dcost = zeros( heightL, widthL, 'single' );
h = zeros(WS,WS,'double'); h(1,1) = 1; h(1,WS) = -1; h(WS,1) = -1; h(WS,WS) = 1;
 
 
for Dc = 1 : D
   maxL = widthL + 1 - Dc; 
   pcost(:, Dc : widthL, Dc ) = imabsdiff( imgright( :, 1 : maxL), imgleft( :, Dc : widthL) );
end
 
 
icost = single(pcost);
icost = cumsum( cumsum( icost ), 2 );
 
 
wcost = imfilter(icost,h,'same','symmetric');
 
 
[ dcost(:,D+WS2:widthL), dmap(:,D+WS2:widthL)] = min( wcost(:,D+WS2:widthL,:),[], 3 );
for j=WS2+1:D+WS2
    [ dcost(:,j), dmap(:,j)] = min( wcost(:, j, 1 : (j - WS2) ),[], 3 );
end
 
 
warning off;
spdmap = single(dmap-1);
 
 
if spacc==1
for j=D+1:widthL
for i=1:heightL
if dmap(i,j)>1 && dmap(i,j)<D
p = polyfit2((single(dmap(i,j)-2:dmap(i,j))),shiftdim(single(wcost(i,j,dmap(i,j)-1:dmap(i,j)+1)),1),2);
temp=roots(p);
spdmap(i,j)=real(temp(1));
end
end
end
end
warning on;