单应图像变换失真问题 [英] Homographic image transformation distortion issue

查看:25
本文介绍了单应图像变换失真问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 3D 转换矩阵转换图像,并假设我的相机是正交的.

I am trying to transform an image using a 3D transformation matrix and assuming my camera is orthonormal.

我正在使用 Hartley 和 Zisserman 第 13 章中给出的平面诱导单应性公式 H=R-t*n'/d(d=Inf 所以 H=R)来定义我的单应性.

I am defining my homography using the plane-induced homography formula H=R-t*n'/d (with d=Inf so H=R) as given in Hartley and Zisserman Chapter 13.

我感到困惑的是,当我使用相当适度的旋转时,图像的扭曲程度似乎比我预期的要大得多(我确定我没有混淆弧度和度数).

What I am confused about is when I use a rather modest rotation, the image seems to be distorting much more than I expect (I'm sure I'm not confounding radians and degrees).

这里可能出了什么问题?

What could be going wrong here?

我已附上我的代码和示例输出.

I've attached my code and example output.

n = [0;0;-1];
d = Inf;

im = imread('cameraman.tif');

 rotations = [0 0.01 0.1 1 10];

 for ind = 1:length(rotations)
       theta = rotations(ind)*pi/180;

       R = [ 1     0           0 ;
           0  cos(theta) -sin(theta);
           0  sin(theta)  cos(theta)];

       t = [0;0;0];

       H = R-t*n'/d;

      tform = maketform('projective',H');
      imT = imtransform(im,tform);

      subplot(1,5,ind) ;
      imshow(imT)
      title(['Rot=' num2str(rotations(ind)) 'deg']);
      axis square
 end

推荐答案

公式 H = R-t*n'/d 有一个假设在您的情况下不满足:

The formula H = R-t*n'/d has one assumption which is not met in your case:

这个公式意味着您使用的是焦距=1的针孔相机模型

但在您的情况下,为了让您的相机更真实并且您的代码能够正常工作,您应该将焦距设置为远大于 1 的某个正数.(焦距是从相机中心到图像的距离飞机)

But in your case, for your camera to be more real and for your code to work, you should set the focal length to some positive number much greater than 1. (focal length is the distance from your camera center to the image plane)

为此,您可以定义一个处理焦距的校准矩阵 K.您只需要将公式更改为H=K R inv(K) - 1/d K t n' inv(K)其中 K 是一个 3×3 单位矩阵,其沿对角线的两个第一个元素设置为焦距(例如 f=300).如果你假设一个投影相机,这个公式很容易推导出来.

To do this you can define a calibration matrix K which handles the focal length. You just need to change your formula to H=K R inv(K) - 1/d K t n' inv(K) in which K is a 3-by-3 identity matrix whose two first elements along the diagonal are set to the focal length (e.g. f=300). The formula can be easily derived if you assume a projective camera.

以下是代码的更正版本,其中角度有意义.

Below is the corrected version of your code, in which the angles make sense.

n = [0;0;-1];
d = Inf;

im = imread('cameraman.tif');

rotations = [0 0.01 0.1 30 60];

 for ind = 1:length(rotations)
   theta = rotations(ind)*pi/180;

   R = [ 1     0           0 ;
       0  cos(theta) -sin(theta);
       0  sin(theta)  cos(theta)];

   t = [0;0;0];

  K=[300 0    0;
        0    300 0;
        0    0    1];

  H=K*R/K-1/d*K*t*n'/K;

  tform = maketform('projective',H');
  imT = imtransform(im,tform);

  subplot(1,5,ind) ;
  imshow(imT)
  title(['Rot=' num2str(rotations(ind)) 'deg']);
  axis square
end

您可以在下图中看到结果:

You can see the result in the image below:

您还可以围绕其中心旋转图像.为此,您应该将图像平面原点设置为图像的中心,我认为使用 matlab(maketform)的方法是不可能的.您可以改用下面的方法.

You can also rotate the image around its center. For it to happen you should set the image plane origin to the center of the image which I think is not possible with that method of matlab (maketform). You can use the method below instead.

imT=imagehomog(im,H','c');

请注意,如果您使用此方法,则必须更改 n、d、t 和 R 中的一些设置才能获得适当的结果.该方法可以在以下位置找到:https://github.com/covarep/covarep/blob/master/external/voicebox/imagehomog.m

Note that if you use this method, you'll have to change some settings in n, d, t and R to get the appropriate result. That method can be found at: https://github.com/covarep/covarep/blob/master/external/voicebox/imagehomog.m

图像同源程序的结果以及 n、d、t 和 R 的一些变化如下所示,看起来更真实.

The result of the program with imagehomog and some changes in n, d, t , and R is shown below which seems more real.

新设置是:

n = [0 0 1]';
d = 2;
t = [1 0 0]';
R = [cos(theta),  0, sin(theta);
     0,           1,          0;
     -sin(theta), 0, cos(theta)];

这篇关于单应图像变换失真问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆