lens distortion - university of minnesotahspark/csci5980/lec2... · assumption: lens distortion is...

of 28 /28
Lens Distortion

Upload: others

Post on 13-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Lens Distortion

Page 2: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model
Page 3: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Lens Radial Distortion

Page 4: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

udistorted

p px y,

Page 5: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

udistorted

p px y,

Lu udistorted undistorted( )ρ

undistorted uρwhere

2 4 L k k1 2( ) 1ρ ρ ρ

uundistorted

Page 6: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model

Lu udistorted undistorted( )ρ

distorted uρwhere

2 4 L k k1 2( ) 1ρ ρ ρ

Lu udistorted undistorted( )ρ

2 4 L k k1 2( ) 1ρ ρ ρ

Page 7: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model

Lu udistorted undistorted( )ρ

distorted uρwhere

2 4 L k k1 2( ) 1ρ ρ ρ

2 4 L k k1 2( ) 1ρ ρ ρ

Lu udistorted undistorted( )ρ

01 k01 k

Page 8: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

udistorted

p px y,

Lu udistorted undistorted( )ρ

undistorted uρwhere

2 4 L k k1 2( ) 1ρ ρ ρ

uundistorted

Page 9: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

udistorted

p px y,

Lu udistorted undistorted( )ρ

where

2 4 L k k1 2( ) 1ρ ρ ρ

uundistorted

Normalized point:

u K u u K u-1 -1distorted distorted undistorted undistorted,

undistorted uρ

Page 10: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

udistorted

p px y,

Lu udistorted undistorted( )ρ

where

2 4 L k k1 2( ) 1ρ ρ ρ

uundistorted

Normalized point:

u K u u K u-1 -1distorted distorted undistorted undistorted,

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

undistorted uρ

Page 11: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

im = imread(‘image.jpg’); f = 1224; k = -0.08; px = size(im,2)/2; py = size(im,1)/2;

Distorted image

Page 12: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

im = imread(‘image.jpg’); f = 1224; k = -0.08; px = size(im,2)/2; py = size(im,1)/2; im_new = zeros(size(im)); % create a new image for i = 1 : size(im,1) for j = 1 : size(im,2)

i,j

Undistorted image Distorted image

Page 13: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

im = imread(‘image.jpg’); f = 1224; k = -0.08; px = size(im,2)/2; py = size(im,1)/2; im_new = zeros(size(im)); % create a new image for i = 1 : size(im,1) for j = 1 : size(im,2) dx = ([j;i]-[px;py])/f; r = norm(dx);

-1undistorted undistortedu K u

i,j

undistorted uρ

Undistorted image Distorted image

Page 14: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

im = imread(‘image.jpg’); f = 1224; k = -0.08; px = size(im,2)/2; py = size(im,1)/2; im_new = zeros(size(im)); % create a new image for i = 1 : size(im,1) for j = 1 : size(im,2) dx = ([j;i]-[px;py])/f; r = norm(dx); l = 1 + k*r*r; x = f*l*dx+[cx;cy];

-1undistorted undistortedu K u

i,j

2 4 L k k1 2( ) 1ρ ρ ρ

distorted distortedKu u

Undistorted image Distorted image

undistorted uρ

Page 15: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

im = imread(‘image.jpg’); f = 1224; k = -0.08; px = size(im,2)/2; py = size(im,1)/2; im_new = zeros(size(im)); % create a new image for i = 1 : size(im,1) for j = 1 : size(im,2) dx = ([j;i]-[px;py])/f; r = norm(dx); l = 1 + k*r*r; x = f*l*dx+[cx;cy]; if floor(x(1))<=0 || floor(x(1))>size(im,2) || floor(x(2))<=0 || floor(x(2))>size(im,1) continue; end im_new(i,j,:) = im(floor(x(2)), floor(x(1)),:); end end

-1undistorted undistortedu K u

i,j

2 4 L k k1 2( ) 1ρ ρ ρ

distorted distortedKu u

Undistorted image Distorted image

undistorted uρ

Page 16: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

im = imread(‘image.jpg’); f = 1224; k = -0.08; px = size(im,2)/2; py = size(im,1)/2; im_new = zeros(size(im)); % create a new image for i = 1 : size(im,1) for j = 1 : size(im,2) dx = ([j;i]-[px;py])/f; r = norm(dx); l = 1 + k*r*r; x = f*l*dx+[cx;cy]; if floor(x(1))<=0 || floor(x(1))>size(im,2) || floor(x(2))<=0 || floor(x(2))>size(im,1) continue; end im_new(i,j,:) = im(floor(x(2)), floor(x(1)),:); end end

-1undistorted undistortedu K u

i,j

2 4 L k k1 2( ) 1ρ ρ ρ

distorted distortedKu u

Undistorted image Distorted image

undistorted uρ

Page 17: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

[[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2);

X Y

XY coordinate

Page 18: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

[[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X_n = (X-px)/f; Y_n = (Y-py)/f;

X Y

XY coordinate

-1undistorted undistortedu K u

Page 19: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

[[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X_n = (X-px)/f; Y_n = (Y-py)/f; r_u = sqrt(X_n.^2+Y_n.^2);

X Y

XY coordinate

-1undistorted undistortedu K u

undistorted uρ

distorted uρ

Page 20: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

[[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X_n = (X-px)/f; Y_n = (Y-py)/f; r_u = sqrt(X_n.^2+Y_n.^2); L = 1 + k * r_u.^2;

XY coordinate

-1undistorted undistortedu K u

2

1( ) 1 L kρ ρ

undistorted uρ

2

1( ) 1 L kρ ρ

Page 21: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

[[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X_n = (X-px)/f; Y_n = (Y-py)/f; r_u = sqrt(X_n.^2+Y_n.^2); L = 1 + k * r_u.^2; X_dist_n = X_n.* L; Y_dist_n = Y_n.* L;

X Y

XY coordinate

-1undistorted undistortedu K u

2

1( ) 1 L kρ ρ

distorted distortedKu u

undistorted uρ

Page 22: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

[[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X_n = (X-px)/f; Y_n = (Y-py)/f; r_u = sqrt(X_n.^2+Y_n.^2); L = 1 + k * r_u.^2; X_dist_n = X_n.* L; Y_dist_n = Y_n.* L;

Xdist Ydist

XY coordinate

-1undistorted undistortedu K u

2

1( ) 1 L kρ ρ

distorted distortedKu u

undistorted uρ

Page 23: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

[[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X_n = (X-px)/f; Y_n = (Y-py)/f; r_u = sqrt(X_n.^2+Y_n.^2); L = 1 + k * r_u.^2; X_dist_n = X_n.* L; Y_dist_n = Y_n.* L; imUndistortion(:,:,1) = reshape(interp2(im(:,:,1), X_dist(:), Y_dist(:)), [h, w]); imUndistortion(:,:,2) = reshape(interp2(im(:,:,2), X_dist(:), Y_dist(:)), [h, w]); imUndistortion(:,:,3) = reshape(interp2(im(:,:,3), X_dist(:), Y_dist(:)), [h, w]);

XY coordinate

-1undistorted undistortedu K u

distorted uρ

2

1( ) 1 L kρ ρ

distorted distortedKu u

11a 12a

21a 22a

Bilinear interpolation

Page 24: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

img

m

ccd

3840= = 0.00153 1224pix

0.0048

Wf f

W

img

x

3840= = 1920pix

2 2

Wp img

y

2160= = 1080pix

2 2

Hp

[[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X_n = (X-px)/f; Y_n = (Y-py)/f; r_u = sqrt(X_n.^2+Y_n.^2); L = 1 + k * r_u.^2; X_dist_n = X_n.* L; Y_dist_n = Y_n.* L; imUndistortion(:,:,1) = reshape(interp2(im(:,:,1), X_dist(:), Y_dist(:)), [h, w]); imUndistortion(:,:,2) = reshape(interp2(im(:,:,2), X_dist(:), Y_dist(:)), [h, w]); imUndistortion(:,:,3) = reshape(interp2(im(:,:,3), X_dist(:), Y_dist(:)), [h, w]);

XY coordinate

-1undistorted undistortedu K u

distorted uρ

2

1( ) 1 L kρ ρ

distorted distortedKu u

Bilinear interpolation

11a 12a

21a 22a

UndistortImageRadial.m

Page 25: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model (MATLAB Efficient) Assumption: Lens distortion is a function of distance from the principal point.

[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X = X(:); Y = Y(:); pt = [X'; Y']; pt = bsxfun(@minus, pt, [px;py]); pt = bsxfun(@rdivide, pt, [f;f]); r_u = sqrt(sum(pt.^2, 1)); pt = bsxfun(@times, pt, 1 + k * r_u.^2); pt = bsxfun(@times, pt, [f;f]); pt = bsxfun(@plus, pt, [px;py]); imUndistortion(:,:,1) = reshape(interp2(im(:,:,1), pt(1,:), pt(2,:)), [h, w]); imUndistortion(:,:,2) = reshape(interp2(im(:,:,2), pt(1,:), pt(2,:)), [h, w]); imUndistortion(:,:,3) = reshape(interp2(im(:,:,3), pt(1,:), pt(2,:)), [h, w]);

-1undistorted undistortedu K u

distorted uρ

2 4 L k k1 2( ) 1ρ ρ ρ

distorted distortedKu u

Bilinear interpolation

i,j

Undistorted image Distorted image

UndistortImageRadial.m

Page 26: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Practice with Your Cellphone Camera Code download: http://www-users.cs.umn.edu/~hspark/CSci5980/code/

im = imread('1227161240_HDR.jpg'); im = double(im); k = -0.05; f = 1224; px = size(im,2)/2; py = size(im,1)/2; [X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X_n = (X-px)/f; Y_n = (Y-py)/f; r_u = sqrt(X_n.^2+Y_n.^2); L = 1 + k * r_u.^2; X_dist_n = X_n.* L; Y_dist_n = Y_n.* L; X_dist = X_dist_n*f + px; Y_dist = Y_dist_n*f + py; imUndistortion(:,:,1) = reshape(interp2(im(:,:,1), X_dist(:), Y_dist(:)), [h, w]); imUndistortion(:,:,2) = reshape(interp2(im(:,:,2), X_dist(:), Y_dist(:)), [h, w]); imUndistortion(:,:,3) = reshape(interp2(im(:,:,3), X_dist(:), Y_dist(:)), [h, w]);

UndistortImageRadial.m

Page 27: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Radial Distortion Model Assumption: Lens distortion is a function of distance from the principal point.

[X, Y] = meshgrid(1:(size(im,2)), 1:(size(im,1))); h = size(X, 1); w = size(X,2); X = X(:); Y = Y(:); pt = [X'; Y']; pt = bsxfun(@minus, pt, [px;py]); pt = bsxfun(@rdivide, pt, [f;f]); r_u = sqrt(sum(pt.^2, 1)); pt = bsxfun(@times, pt, 1 + k * r_u.^2); pt = bsxfun(@times, pt, [f;f]); pt = bsxfun(@plus, pt, [px;py]); imUndistortion(:,:,1) = reshape(interp2(im(:,:,1), pt(1,:), pt(2,:)), [h, w]); imUndistortion(:,:,2) = reshape(interp2(im(:,:,2), pt(1,:), pt(2,:)), [h, w]); imUndistortion(:,:,3) = reshape(interp2(im(:,:,3), pt(1,:), pt(2,:)), [h, w]);

Page 28: Lens Distortion - University of Minnesotahspark/CSci5980/Lec2... · Assumption: Lens distortion is a function of distance from the principal point. ppud xy, Radial Distortion Model

Lens Radial Distortion Correction