function [DisparityImage,diffDCval] = GetDisparityImage(left,right) [rows,cols] = size(left); corr = 2; % Compensate for differing DC values diffDCval = mean(mean(left)) - mean(mean(right)); right = right + diffDCval; for rr = 1 : rows for cc = 1 : cols pixVal = right(rr,cc); % now calculate the disparity in the right image along epipolar line disparity = 0; rowDiff = abs( left(rr,:) - pixVal ) + 3*abs((1:cols) - cc + corr); [difference,disparity] = min(rowDiff); DisparityImage(rr,cc) = disparity - cc; DifferenceImage(rr,cc) = difference; end end % meanDisparity = mean(mean(DisparityImage)) % maxDifference = max(max(DifferenceImage)) % meanDifference = mean(mean(DifferenceImage))