美文网首页matlab学习
matlab 图像反畸变

matlab 图像反畸变

作者: Kerwin_H | 来源:发表于2019-06-21 09:28 被阅读0次

    %图像畸变

    clear

    A =[720 0 360; 

        0    810 405; 

        0 0 1]; 

    D = [-0.267 0.636 0 0 0]; 

    fx = A(1,1); 

    fy = A(2,2); 

    cx = A(1,3); 

    cy = A(2,3); 

    k1 = D(1); 

    k2 = D(2); 

    k3 = D(5); 

    p1 = D(3); 

    p2 = D(4); 

    K = A; 

    Idistorted = imread('F:\a01.png'); 

    Idistorted = rgb2gray(Idistorted); 

    Idistorted = im2double(Idistorted); 

    I = zeros(size(Idistorted)); 

    [i, j] = find(~isnan(I)); 

    % Xp = the xyz vals of points on the z plane 

    Xp = (K)\[j i ones(length(i),1)]'; 

    % Now we calculate how those points distort i.e forward map them through the distortion 

    r2 = Xp(1,:).^2+Xp(2,:).^2; 

    x = Xp(1,:); 

    y = Xp(2,:); 

    x = x.*(1+k1*r2 + k2*r2.^2 + k3*r2.^3) + 2*p1.*x.*y + p2*(r2 + 2*x.^2); 

    y = y.*(1+k1*r2 + k2*r2.^2 + k3*r2.^3) + 2*p2.*x.*y + p1*(r2 + 2*y.^2); 

    % u and v are now the distorted cooridnates 

    u = reshape(fx*x + cx,size(I)); 

    v = reshape(fy*y + cy,size(I)); 

    % Now we perform a backward mapping in order to undistort the warped image coordinates 

    I = interp2(Idistorted, u, v); 

    subplot(121); imagesc(Idistorted); 

    subplot(122); imagesc(I);

    imwrite(I,'a04.png') %export picture

    相关文章

      网友评论

        本文标题:matlab 图像反畸变

        本文链接:https://www.haomeiwen.com/subject/gtpeqctx.html