-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathGetIPMImage.m
67 lines (58 loc) · 1.81 KB
/
GetIPMImage.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
63
64
65
66
67
%% LoadInfo [cameraInfo, ipmInfo]
[cameraInfo, ipmInfo] = GetInfo;
% GetInfo the information IPM need
%% IPM
outImage = zeros(ipmInfo.ipmHeight,ipmInfo.ipmWidth);
I = imread('IMG00996.jpg');
R = I(:,:,1);
[Rheight, Rwidth] = size(R);
u = Rheight;
v = Rwidth;
vpp = GetVanishingPoint(cameraInfo);
vp.x = vpp(1);
vp.y = vpp(2);
uvLimitsp = [ vp.x, ipmInfo.ipmRight, ipmInfo.ipmLeft, vp.x;
ipmInfo.ipmTop, ipmInfo.ipmTop, ipmInfo.ipmTop, ipmInfo.ipmBottom];
xyLimits = TransformImage2Ground(uvLimitsp,cameraInfo);
row1 = xyLimits(1,:);
row2 = xyLimits(2,:);
xfMin = min(row1); xfMax = max(row1);
yfMin = min(row2); yfMax = max(row2);
[outRow outCol] = size(outImage);
stepRow = (yfMax - yfMin)/outRow;
stepCol = (xfMax - xfMin)/outCol;
xyGrid = zeros(2,outRow*outCol);
y = yfMax-0.5*stepRow;
for i = 1:outRow
x = xfMin+0.5*stepCol;
for j = 1:outCol
xyGrid(1,(i-1)*outCol+j) = x;
xyGrid(2,(i-1)*outCol+j) = y;
x = x + stepCol;
end
y = y - stepRow;
end
%TransformGround2Image
uvGrid = TransformGround2Image(xyGrid,cameraInfo);
% mean value of the image
means = mean(R(:))/255;
RR = double(R)/255;
for i=1:outRow
for j = 1:outCol;
ui = uvGrid(1,(i-1)*outCol+j);
vi = uvGrid(2,(i-1)*outCol+j);
if (ui<ipmInfo.ipmLeft || ui>ipmInfo.ipmRight || vi<ipmInfo.ipmTop || vi>ipmInfo.ipmBottom)
outImage(i,j) = means;
else
x1 = int32(ui); x2 = int32(ui+1);
y1 = int32(vi); y2 = int32(vi+1);
x = ui-double(x1) ; y = vi-double(y1);
val = double(RR(y1,x1))*(1-x)*(1-y)+double(RR(y1,x2))*x*(1-y)+double(RR(y2,x1))*(1-x)*y+double(RR(y2,x2))*x*y;
outImage(i,j) = val;
end
end
end
%% show the result
figure,imshow(outImage);
%% save image
imwrite(outImage,'pp.jpg');