仿射变换实施

时间:2013-03-22 02:38:17

标签: c++ visual-studio-2010 mfc affinetransform

我正在尝试在两个图像上实现仿射变换。 首先,我在两个图像中找到匹配对。其中一个是缩放图像,另一个是参考图像。这些对使我恢复了效率:

     |1   0 |      | x |       |  1  |
A  = |      |  X = |   |   B = |     |
     |0   0 |      | y |       | 221 |   

The equation formed is X' = AX + B;

x_co_efficients[2] = (((x_new_Cordinate[2]-x_new_Cordinate[0])*(xCordinate[1]- xCordinate[0])) - ((x_new_Cordinate[1]-x_new_Cordinate[0])*(xCordinate[2] - xCordinate[0])))/
    (((xCordinate[1]-xCordinate[0])*(yCordinate[2]-yCordinate[0])) - ((xCordinate[2]-xCordinate[0])*(yCordinate[1]-yCordinate[0])));

x_co_efficients[1] = ((x_new_Cordinate[1]-x_new_Cordinate[0]) - (yCordinate[1]-yCordinate[0])*(x_co_efficients[2]))/(xCordinate[1]-xCordinate[0]);

x_co_efficients[0] = x_new_Cordinate[0] - (((x_co_efficients[1])*(xCordinate[0])) + ((x_co_efficients[2])*(yCordinate[0])));



y_co_efficients[2] = (((y_new_Cordinate[2]-y_new_Cordinate[0])*(xCordinate[1]- xCordinate[0])) - ((y_new_Cordinate[1]-y_new_Cordinate[0])*(xCordinate[2] - xCordinate[0])))/
    (((xCordinate[1]-xCordinate[0])*(yCordinate[2]-yCordinate[0])) - ((xCordinate[2]-xCordinate[0])*(yCordinate[1]-yCordinate[0])));

y_co_efficients[1] = ((y_new_Cordinate[1]-y_new_Cordinate[0]) - (yCordinate[1]-yCordinate[0])*(y_co_efficients[2]))/(xCordinate[1]-xCordinate[0]);

y_co_efficients[0] = y_new_Cordinate[0] - (((y_co_efficients[1])*(xCordinate[0])) + ((y_co_efficients[2])*(yCordinate[0])));

这些是我习惯于使用匹配对来获得系数的公式。方程式对于相同的图像工作正常,对于缩放图像,它给了我那些系数。现在问题是我有一个24位二进制图像,我想在该图像上实现关于参考的仿射变换。现在,当我试图找到该图像的新坐标并将其当前值更改为该坐标时,我得到了一个非常扭曲的图像。如果转型是正确的,那就不应该得到。 有人可以看一下方程式,并解释一下如何在第二张图像上实现这些方程式。 我的代码是用C ++编写的。谢谢。 This is my reference image

我的参考图像在上面..我的比较图像是 enter image description here

我得到的结果是只有线条的扭曲图像。 enter image description here

修改1

我现在已将解决方法更改为矩阵。现在我得到正确的输出,但我注册后的图像是这样的.. 此外,我必须在新的坐标中应用0到320 * 240的限制来获得像素值。现在我的结果有点像这样。 enter image description here

编辑2

我更改了代码并获得了没有任何黑色像素的结果。我有点倾斜..虽然已经删除了给定图像中的缩放效果。 enter image description here

1 个答案:

答案 0 :(得分:0)

您的转换矩阵A存在问题。它会破坏y坐标值并将221分配给所有y坐标

你可以在A中的(2,2)处的元素只做1,问题应该解决。

相关问题