function UndistortImageRadial

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]);

imUndistortion = uint8(imUndistortion);
figure(1)
clf;
imshow(imUndistortion);

