Line | |
---|
1 | function [x] = comp_distortion_oulu(xd,k);
|
---|
2 |
|
---|
3 | %comp_distortion_oulu.m
|
---|
4 | %
|
---|
5 | %[x] = comp_distortion_oulu(xd,k)
|
---|
6 | %
|
---|
7 | %Compensates for radial and tangential distortion. Model From Oulu university.
|
---|
8 | %For more informatino about the distortion model, check the forward projection mapping function:
|
---|
9 | %project_points.m
|
---|
10 | %
|
---|
11 | %INPUT: xd: distorted (normalized) point coordinates in the image plane (2xN matrix)
|
---|
12 | % k: Distortion coefficients (radial and tangential) (4x1 vector)
|
---|
13 | %
|
---|
14 | %OUTPUT: x: undistorted (normalized) point coordinates in the image plane (2xN matrix)
|
---|
15 | %
|
---|
16 | %Method: Iterative method for compensation.
|
---|
17 | %
|
---|
18 | %NOTE: This compensation has to be done after the subtraction
|
---|
19 | % of the principal point, and division by the focal length.
|
---|
20 |
|
---|
21 |
|
---|
22 | if length(k) == 1,
|
---|
23 |
|
---|
24 | [x] = comp_distortion(xd,k);
|
---|
25 |
|
---|
26 | else
|
---|
27 |
|
---|
28 | k1 = k(1);
|
---|
29 | k2 = k(2);
|
---|
30 | k3 = k(5);
|
---|
31 | p1 = k(3);
|
---|
32 | p2 = k(4);
|
---|
33 |
|
---|
34 | x = xd; % initial guess
|
---|
35 |
|
---|
36 | for kk=1:20,
|
---|
37 |
|
---|
38 | r_2 = sum(x.^2);
|
---|
39 | k_radial = 1 + k1 * r_2 + k2 * r_2.^2 + k3 * r_2.^3;
|
---|
40 | delta_x = [2*p1*x(1,:).*x(2,:) + p2*(r_2 + 2*x(1,:).^2);
|
---|
41 | p1 * (r_2 + 2*x(2,:).^2)+2*p2*x(1,:).*x(2,:)];
|
---|
42 | x = (xd - delta_x)./(ones(2,1)*k_radial);
|
---|
43 |
|
---|
44 | end;
|
---|
45 |
|
---|
46 | end;
|
---|
47 |
|
---|
48 | |
---|
Note: See
TracBrowser
for help on using the repository browser.