-
Notifications
You must be signed in to change notification settings - Fork 0
/
RectifyImagePair.m
62 lines (51 loc) · 1.61 KB
/
RectifyImagePair.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function [rectImgL, rectImgR, xRangeL, xRangeR,maskL,maskR] = RectifyImagePair(stereoParam, imgLeft, imgRight)
% RectifyImagePair performs rectification on image pair specified by
% imgFileLeft and imgFileRight.
% By Ji Zhou
if ischar(imgLeft)
imgL = imread(imgLeft);
else
imgL = imgLeft;
end
if ischar(imgRight)
imgR = imread(imgRight);
else
imgR = imgRight;
end
imgSize = size(imgLeft);
imgSize = imgSize(1:2);
if 0 %% 20200702
[rectParamL, rectParamR] = GetRectifyParam(stereoParam, size(imgL));
else
[rectParamL, rectParamR] = GetRectifyParam2(stereoParam, size(imgL));
end
[rectImgL, xRangeL0, maskL] = RectifyOneImage(imgL, rectParamL);
[rectImgR, xRangeR0, maskR] = RectifyOneImage(imgR, rectParamR);
dltL = imgSize(2) - xRangeL0(2);
dltR = xRangeR0(1);
dlt = min(dltL,dltR);
if 1
if abs(diff(xRangeL0)) > abs(diff(xRangeR0))
xRangeR0(1) = xRangeR0(1) - abs((abs(diff(xRangeL0)) - abs(diff(xRangeR0))));
else
xRangeL0(2) = xRangeL0(2) + abs((abs(diff(xRangeL0)) - abs(diff(xRangeR0))));
end
xRangeR0 = xRangeR0 + size(imgL,2);
xRangeL = xRangeL0;
xRangeR = xRangeR0;
else
xRangeL = [1 imgSize(2) + dlt];
xRangeR = [imgSize(2)-dlt+1 imgSize(2)*2];
end
% % % % % % % % % % % % % ShowStereoPair(rectImgL, rectImgR);
% % % % imshow([rectImgL rectImgR]);
% % % % figure, imshowpair(rectImgL,rectImgR);
end
function ShowStereoPair(imgLeft, imgRight)
[imgH,imgW, numChnl] = size(imgLeft);
splitW = 10;
imgDisp = zeros(imgH, 2*imgW+splitW, numChnl, 'uint8');
imgDisp(:,1:imgW, :) = imgLeft;
imgDisp(:,(1:imgW)+splitW+imgW, :) = imgRight;
figure, imshow(imgDisp);
end