function disp = correlation_matching(left, right,x,y) % This function creates a disparity map from a pair of stereo images. % Use left as reference. left = double(left); right = double(right); % Parameters based on a 419x419 grayscale image. w = 5; %pixels wide %x = 210; %fixed in the middle %y = 120; %about a third into the image fy = y; %limit = y+w lw = y-w; upr = y+w; k = 2 %iterations best = 0; for j = 0:k cum = 0; for i = lw:upr i i+j %buff(x,i) = left(x,i)*right(x,i+j); cum = cum + (right(x,i) - left(x,i+j))^2 end %y = y+1; best if cum > best best = cum; besty = y+j end end %buff best y besty