资源简介

基于动态规划的立体匹配代码-使用MATLAB实现。此代码已经将各个参数调试完毕,下载后可直接运行。在学习的道路上希望大家相互帮助。。。这是第一次上传代码,若大家喜欢的话在后期还会继续上传一些立体匹配的源代码,供大家学习与参考。

资源截图

代码片段和文件信息

%A script that processes rectified stereo image pair to generate disparity map
%using dynamic programming
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Cox Ingemar J. Sunita L. Hingorani Satish B. Rao and Bruce M. Maggs. 
%“A maximum likelihood stereo algorithm.“ Computer vision and image understanding 63 
%no. 3 (1996): 542-567.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clearvars;
% close all;
I_1 = imread(‘_left.png‘); %Read Left Image
I_2 = imread(‘_right.png‘); %Read Right Image with same size as the Left
[nRow nColnChannel] = size(I_1);
if(nChannel==3)
    I_1 = rgb2gray(I_1);
    I_2 = rgb2gray(I_2);
end
I_1 = im2double(I_1);
I_2 = im2double(I_2);

figure;imshow(I_1);
figure;imshow(I_2);

C = zeros(nCol nCol);
M = ones(size(C));
displeft = zeros(nRow nCol);
dispright = zeros(nRow nCol);
occ = 0.0009; %Occlusion cost
for row = 1:nRow
%     row %To display which row of the image is being processed
    for i=2:nCol
        C(i1) = i*occ;
    end
    for j = 2:nCol
       C(1j) = j*occ; 
    end
    for i = 2:nCol
        for j = 2:nCol
           temp = (I_1(rowi)-I_2(rowj))^2;

            min1 = C(i-1j-1)+temp;
            min2 = C(i-1j)+occ;
            min3 = C(ij-1)+occ;
            cmin = min([min1min2min3]);
            C(ij) = cmin; % Cost Matrix
            if(cmin==min1)
                M(ij) = 1; %Path Tracker
            elseif(cmin==min2)
                M(ij) = 2;
            elseif(cmin==min3)
                M(ij) = 3;
            end
        end
    end

    i = nCol;
    j = nCol;
    while(i~=1 && j~=1)

       switch M(ij)
           case 1
               displeft(rowi) = abs(i-j); % Disparity Image in Left Image coordinates
               dispright(rowj) = abs(j-i); % Disparity Image in Right Image coordinates
               j = j-1;
               i = i-1;
           case 2
               displeft(rowi) = NaN;
               i = i-1;
           case 3
               dispright(rowj) = NaN;
               j = j-1;
       end
    end
    clear C M
end
figure;imshow(displeft[0255]);
figure;imshow(dispright[0255]);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2171  2020-04-08 21:40  Dynamic_Programming_Stereo_Matching-master\Dynamic_programming_stereo_matching.m
     文件         404  2017-10-03 17:28  Dynamic_Programming_Stereo_Matching-master\README.md
     文件      358802  2017-10-03 17:28  Dynamic_Programming_Stereo_Matching-master\_left.png
     文件      358496  2017-10-03 17:28  Dynamic_Programming_Stereo_Matching-master\_right.png
     文件       18431  2018-11-09 22:03  Dynamic_Programming_Stereo_Matching-master\left.jpg
     文件       18366  2018-11-09 22:03  Dynamic_Programming_Stereo_Matching-master\right.jpg
     目录           0  2020-04-08 21:40  Dynamic_Programming_Stereo_Matching-master\

评论

共有 条评论