Uncertainty - examples 1

advertisement
Uncertainty - examples
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
1
Range example
• A camera takes a picture of a distant flagpole that is 10 meters in height.
The height of the flagpole in the image is 20 pixels. The effective focal
length of the camera is 1000 pixels.
– What is the range to the flagpole?
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
2
Range example
• A camera takes a picture of a distant flagpole that is 10 meters in height.
The height of the flagpole in the image is 20 pixels. The effective focal
length of the camera is 1000 pixels.
– What is the range to the flagpole?
•
Solution:
–
–
–
Let H=10 m be the height of the pole, and h=20 pixels be the height in the image.
By similar triangles, H/Z = h/f, where f=1000 pixels is the focal length of the camera.
So Z = f H/h = (1000pix)(10 m)/(20 pix) = 500 m
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
3
Range example
• Assume that the only source of error is the (supposedly known) focal
length of the camera. If the standard deviation of the error in the focal
length is 100 pixels, what is the uncertainty in the range?
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
4
Range example
• Assume that the only source of error is the (supposedly known) focal
length of the camera. If the standard deviation of the error in the focal
length is 100 pixels, what is the uncertainty in the range?
• Solution
– Taking total derivative of each side,
–
dZ = df H/h
–
= (100 pix)(10 m)/(20 pix)
–
= 1000/20 = 50m
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
5
Range example
• Now assume that the only source of error is the (supposedly known)
length of the flagpole. If the standard deviation of the error in the length
of the flagpole is 2 pixels, what is the uncertainty in the range?
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
6
Range example
• Now assume that the only source of error is the (supposedly known)
length of the flagpole. If the standard deviation of the error in the length
of the flagpole is 2 pixels, what is the uncertainty in the range?
• Solution
–
Taking total derivative of each side,
–
dZ = dh f H/h^2
– = (2 pix)(1000 pix)(10 m)/(20^2 pix^2)
–
= 20000/400 = 50m
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
7
Stereo example
• Simulate a stereo configuration, with two identical cameras side by
side, pointing straight ahead
– Pick a value for the focal length f
– Pick a value for the baseline distance b
• Simulate the observation of a point P
– Pick a value for Z
– Compute the disparity for the projection of the point
• Now assume the baseline and disparity have some uncertainty
– The errors have a Gaussian pdf with zero mean
– The errors are independent of each other
– Pick a value for sb, sd
• What is the uncertainty in Z?
•
Plot sZ as a function of b, f
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
8
% See effect of stereo errors
% Create a test case
f = 1000;
% focal length in pixels
b = 0.1;
% Baseline distance (meters)
z = 2.0;
% We look at something at this distance (m)
fprintf('focal length = %f pixels\n', f);
fprintf('baseline = %f m\n', b);
fprintf('Object distance z = %f m\n', z);
d = f*b/z; % disparity
fprintf('Disparity = %f pixels\n', d);
sb = 0.01;
sf = 10;
% Sigma for uncertainty in b
% Sigma for uncertainty in f
% See effect of b,f on error in z
bvals = 0.05:0.01:0.2;
% Possible values for b
fvals = 800:100:2000;
% Possible values for f
nb = length(bvals);
nf = length(fvals);
zs = zeros(nf,nb);
for i=1:nb
b = bvals(i);
for j=1:nf
f = fvals(j);
d = f*b/z; % disparity
J = [ b/d f/d -f*b/(d^2) ];
Cx = [ 0 0
0;
0 sb^2
0;
0 0
sf^2];
Cz = J*Cx*J';
zs(j,i) = sqrt(Cz);
end
end
surf(bvals, fvals, zs);
xlabel('b (m)');
ylabel('f (pix)');
zlabel('sigma z');
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
9
• Note how z error
• So for most accurate
results, have a long
baseline and a long
focal length
1.4
1.2
1
sigma z
– increases as b
(baseline)
decreases
– increases as f (focal
length) decreases
0.8
0.6
0.4
0.2
2000
0
0.05
1500
0.1
1000
0.15
0.2
• Of course, this will
limit the possible
range of disparities
that you can
observe
0.25
500
f (pix)
b (m)
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
10
2D transformation example
• An object undergoes a 2D rigid transformation from one
image to another
• A 2D rigid transform (rotation + translation) is
 xB   c  s t x  x A 
  
 
y

s
c
t
where c  cos q , s  sin q
 B 
t  y A ,
 1   0 0 1  1 
  
 
• We have N corresponding points
x
(i )
B
, yB(i )   xA(i ) , y A(i ) , i  1 N
• We want to solve for the transformation parameters (q, tx, ty)
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
11
Example
% Using imtool, we find corresponding
% points (x;y), which are the four
% corners of the book
pA = [
213 398 401 223;
29
20 293 297];
pB = [
207 391 339 164;
7
34 302 270];
N = size(pA,2);
“A”
12
“B”
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
2D transformation example
• Solving for transformation
– Recall how we solved for the transformation using nonlinear least squares (see lecture 14)
– Review that method
– Run the Matlab code to find the transformation between
the two images
• Now estimate the uncertainty
– For simplicity, assume that points in image A have no
uncertainty
– Assume that points in image B have uncertainty
• Each coordinate (x,y) is has a Gaussian pdf with sigma = 2.0 pixels
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
13
% Do 2D rigid alignment
clear all
close all
IA = imread('Picture1.jpg');
IB = imread('Picture2.jpg');
figure, imshow(IA,[]);
figure, imshow(IB,[]);
% Using imtool, we find corresponding
% points (x;y), which are the four
% corners of the book
pA = [
213 398 401 223;
29
20 293 297;
1
1
1
1];
pB = [
207 391 339 164;
7
34 302 270];
N = size(pA,2);
theta = 0;
tx = 5.0;
ty = -64;
x = [theta; tx; ty];
% initial guess
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
14
while true
disp('Parameters (theta; tx; ty):'), disp(x);
y = fRigid(x, pA); % Call function to compute expected measurements
dy = reshape(pB,[],1) - y;
% new residual
J = zeros(2*N,3);
% Fill in values of J …
theta = x(1);
for i=1:N
J( 2*(i-1)+1, :) = [ -sin(theta)*pA(1,i)-cos(theta)*pA(2,i)
J( 2*(i-1)+2, :) = [ cos(theta)*pA(1,i)-sin(theta)*pA(2,i)
end
dx = pinv(J)*dy;
1
0
0 ];
1 ];
% Stop if parameters are no longer changing
if abs( norm(dx)/norm(x) ) < 1e-6
break;
end
x = x + dx;
% add correction
end
% Apply transform to image
theta = x(1);
tx = x(2);
ty = x(3);
A = [cos(theta) -sin(theta) tx;
sin(theta) cos(theta) ty;
0 0 1];
T = maketform('affine', A');
I2 = imtransform(IA,T, ...
'XData', [1 size(IA,2)], ...
'YData', [1 size(IA,1)] );
figure, imshow(I2,[]);
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
15
%%%%%%%%%%%%%%%%%%%%%%
% Estimate covariance of parameters
sig = 2.0; % Uncertainty of each point measurement (x or y)
Cp = sig^2 * eye(2*N);
Jp = pinv(J);
Cx = Jp*Cp*Jp';
disp(Cx);
fprintf('Sigma for theta (radians): %f\n', sqrt(Cx(1,1)));
fprintf('Sigma for tx (pixels): %f\n', sqrt(Cx(2,2)));
fprintf('Sigma for ty (pixels): %f\n', sqrt(Cx(3,3)));
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
16
Results
Parameters (theta; tx; ty):
0.2003
4.4577
-64.7366
0.0000 0.0082 -0.0102
0.0082 2.7895 -2.2230
-0.0102 -2.2230 3.7615
Sigma for theta (radians): 0.006137
Sigma for tx (pixels): 1.670180
Sigma for ty (pixels): 1.939458
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
17
Point projection example
• A 3D point P = (X,Y,Z)T is projected onto an image to
an image point p
– P is in the camera’s coordinate system
– Assume projective projection, with values for f, cx, cy
• Assume P is uncertain, with covariance CP
• What is the covariance Cp of the image point p?
• Project that into the image as an ellipse
– Knowing the region where the point is likely to be found
helps when searching for a point match
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
18
clear all
close all
% Project point uncertainty onto an image
f = 600;
% Make up a camera
cx = 200;
cy = 200;
I = ones(400,400);
imshow(I);
%
X
Y
Z
Define a point in camera coordinates
= 1.0;
= 0.5;
= 8.0;
px = f*X/Z + cx;
py = f*Y/Z + cy;
hold on
plot(px,py,'r*');
% Now assume point position is uncertain.
% Define a covariance matrix CP.
sx = 0.05;
sy = 0.05;
sz = 0.5;
CP = [ sx^2 0 0; 0 sy^2 0; 0 0 sz^2 ];
% Project uncertainty onto image
% We know the function to project onto the image, p = g(P).
% g(P) = [ f*X/Z+cx; f*Y/Z+cy ]
% Cp = J CP J', where J = dg/dP.
% J = [ dg1/dX dg1/dY dg1/dZ;
%
dg2/dX dg2/dY dg2/dZ ]
%
= [ f/Z
0
-fX/Z^2;
%
0
f/Z -fY/Z^2 ]
J = [ f/Z
0
0
f/Z
-f*X/(Z^2) ;
-f*Y/(Z^2) ];
Cp = J*CP*J';
disp(Cp);
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
19
% We will draw the ellipse defined by the curve x' Cinv x = z^2,
% where Cinv = Cp^-1. For z=3, this is the 97% probability contour.
z = 3;
% Let y = Rx, where R is the rotation matrix that aligns the axes.
% Then y'*D*y = z^2, where D is a diagonal matrix.
% Or, x'R'*D*Rx = z^2. x'(R'DR)x = z^2.
% So Cinv = R'DR. This is just taking the SVD of Cinv.
[U,S,V] = svd(inv(Cp));
R = V;
% The length of the ellipse axes are len=1/sqrt(Si/z^2)
% where Si is the ith eigenvalue
xrad = sqrt( z^2 / S(1,1) );
yrad = sqrt( z^2 / S(2,2) );
% Generate the points on the curve
x = -xrad:0.1:xrad;
for i=1:length(x)
y(i) = yrad * sqrt( 1 - (x(i)^2)/(xrad^2) );
Y = R' * [x(i); y(i)];
xr(i) = Y(1)+px;
yr(i) = Y(2)+py;
end
hold on
plot(xr,yr);
for i=1:length(x)
y(i) = -yrad * sqrt( 1 - (x(i)^2)/(xrad^2) );
Y = R' * [x(i); y(i)];
xr(i) = Y(1)+px;
yr(i) = Y(2)+py;
end
hold on
plot(xr,yr);
% Solve for y
% Solve for y
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
20
Results
• Image covariance
matrix:
36.0352 10.9863
10.9863 19.5557
EGGN 512 Computer Vision Colorado School of Mines, Engineering Division
Prof. William Hoff
21
Download