【问题标题】:Rectify a photo in Matlab在 Matlab 中校正照片
【发布时间】:2019-12-18 07:59:15
【问题描述】:

我正在处理一些公路照片,我必须转换捕捉到的视角。我的目标是将道路变成一个广场。我的照片看起来和这张类似:

但是,我需要将道路做成正方形,而不是三角形或梯形,这样我才能在上面工作。

我有我照片中的俯仰角、偏航角和滚动角。

我正在尝试这个:

roll_x = 178.517332325424462;
pitch_y = -0.829084891331837937;
pan_z = -0.668910403057581759;

%% Transform perspective
img = imread('imageLoaded.png');
R_rot = R_z(pan_z)*R_y(pitch_y)*R_x(roll_x);

R_2d  = [   R_rot(1,1)  R_rot(1,2) 0; 
        R_rot(2,1)  R_rot(2,2) 0;
        0           0          1    ];
tform = affine2d(R_2d);
outputImage = imwarp(img,tform);
figure(1);
imshow(outputImage);


%% Matrix for Yaw-rotation about the Z-axis
function [R] = R_z(psi)
    R = [cosd(psi) -sind(psi) 0;
         sind(psi)  cosd(psi) 0;
         0          0         1];
end

%% Matrix for Pitch-rotation about the Y-axis
function [R] = R_y(theta)
    R = [cosd(theta)    0   sind(theta);
         0              1   0          ;
         -sind(theta)   0   cosd(theta)     ];
end

%% Matrix for Roll-rotation about the X-axis
function [R] = R_x(phi)
    R = [1  0           0;
         0  cosd(phi)   -sind(phi);
         0  sind(phi)   cosd(phi)];
end

但我正在旋转图像,而不是转换它。我怎样才能实现我的目标?

【问题讨论】:

    标签: matlab image-processing toolbox


    【解决方案1】:

    MATLAB 有 fitgeotrans,这个函数可以从您可以手动定义的点中找到仿射变换,您可以直接使用它或尝试确定您的变换出了什么问题。

    也就是说,仿射变换不是您所需要的。来自this的最后一页:

    仿射变换可保持平行度,这是将梯形道路变换为正方形时所无法做到的。您需要一个投影变换(单应性)。

    请参阅this StackOverflow answer 了解如何操作。

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 2015-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多