-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRightSADCost.m
25 lines (18 loc) · 898 Bytes
/
RightSADCost.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function [disparityLeft] = RightSADCost(img_left, img_right, MaxDisparity)
disp('Begin RightSADCost');
blockSize = 21;
halfBlock = round(blockSize / 2);
disparityLeft = zeros(size(img_left));
for i = halfBlock + 1:size(img_left, 1) - halfBlock
for j = halfBlock + 1:size(img_left, 2) - halfBlock
blockRight = img_right(i - halfBlock:i + halfBlock, j - halfBlock:j + halfBlock);
for k = 0:min(MaxDisparity, size(img_left, 2) - halfBlock - j)
blockLeft = img_left(i - halfBlock:i + halfBlock, j - halfBlock + k:j + halfBlock + k);
% calculate SAD
sadValue(k + 1, 1) = sum(abs(blockLeft(:) - blockRight(:)));
end
[x disparity] = min(sadValue);
disparityLeft(i, j) = (disparity - 1);
end
end
disp('End RightSADCost');