Clear Filters
Clear Filters

Distortion Estimate based on k/p parameters

3 views (last 30 days)
I'm trying to get a manual estimate of the distortion from my lens calibration. For example if I know the k1 parameter I want to estimate the actual shift of a pixel in an image. Going through the code/theory I know that
x_d = x ( 1 + k1 * r^2 )
y_d = y ( 1 + k2 * r^2 )
From the code, I understand that the x/y is not expressed in pixels, but rather as a principal point corrected, focal length adjusted value, i.e.
x = ( x[pix] - pp_x[pix] ) / FL_x[pix]
y = ( y[pix] - pp_y[pix] ) / FL_y[pix]
Applying this to an nominal system I can calculate the pixel shift in the corner (i.e. Delta x = 134.8pix, Delta y = 75.8pix).
However, when I run the "undistortImage" function on the same image, I get a different value (i.e. Delta x = 86pix, Delta y = 49pix).
image1=imread('c:\temp\checker_in.png');
cameraParams2 = cameraParameters('IntrinsicMatrix', [1600,0,0;0,1600,0;640,360,1], 'RadialDistortion', [1.0, 0], 'TangentialDistortion', [0, 0]);
image2=undistortImage(image1,cameraParams2, "linear",'FillValues',[255,255,255],OutputView="same");
imshow(image2);
imwrite(image2, 'c:\temp\checker_out.png');

Answers (1)

SOUMNATH PAUL
SOUMNATH PAUL on 23 Jan 2024
Hi,
The formulae you have given considers only radial distortion with the 'k1' parameter. Here is a script that calculates the pixel shift manually based on the given formulas:
% Given parameters
k1 = 1.0;
pp_x = 640; % Principal point x in pixels
pp_y = 360; % Principal point y in pixels
FL_x = 1600; % Focal length x in pixels
FL_y = 1600; % Focal length y in pixels
% Pixel coordinates in the corner of the image (assuming a certain image size)
x_pix = 134.8; % Delta x in pixels from the principal point
y_pix = 75.8; % Delta y in pixels from the principal point
% Convert pixel coordinates to normalized image coordinates
x = (x_pix - pp_x) / FL_x;
y = (y_pix - pp_y) / FL_y;
% Calculate the radial distance r
r = sqrt(x^2 + y^2);
% Apply radial distortion
x_d = x * (1 + k1 * r^2);
y_d = y * (1 + k1 * r^2);
% Convert distorted coordinates back to pixel coordinates
x_d_pix = x_d * FL_x + pp_x;
y_d_pix = y_d * FL_y + pp_y;
% Calculate pixel shift
delta_x = x_d_pix - x_pix;
delta_y = y_d_pix - y_pix;
% Display the results
fprintf('Manual estimate of pixel shift:\n');
Manual estimate of pixel shift:
fprintf('Delta x: %.2f pixels\n', delta_x);
Delta x: -66.31 pixels
fprintf('Delta y: %.2f pixels\n', delta_y);
Delta y: -37.30 pixels
Hope it helps!
Regards,
Soumnath

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!