尝试仅使用图像导出二维变换矩阵

发布于 2024-08-13 05:46:25 字数 543 浏览 4 评论 0原文

我不知道这是否应该放在数学论坛或编程论坛中,但我会将其发布在两个论坛中,看看我得到了什么。

我有两张计算机图像...其中一张是“原始”图像(一个大的 TIF 文件)。另一张是原始图像的转换版本……它在软件程序中经过旋转、剪切和翻译。我需要对转换后的图像进行一些处理,但我需要原始图像中每个像素的 (xy) 坐标才能完成计算。

我知道图像是通过 3x3 变换矩阵进行旋转和剪切的。如果我有矩阵,我可以自己从第一张图像导出第二张图像(反之亦然)。我不知道它到底旋转、剪切或平移了多少,所以我不能仅仅从一组已知的变换中导出矩阵。我所拥有的是每个图像中的一组对应点(角点等)及其对应的(x,y)坐标。所以这是我的困境:

使用一组相应的变换点((x,y) - >(x',y'),其中三个或更多),我可以导出用于将一个图像转换为的变换矩阵另一个?如果我可以导出矩阵,我就可以求解所有像素(所有 1800 万个像素)的原始坐标,并完成我需要做的计算。

有人可以帮忙吗?我熟悉线性代数......只是不够熟悉,无法在不费尽心思的情况下推导出这一点。任何事情都值得赞赏!

  • 麦克风

I dunno if this should go in a Math forum or a Programming forums, but I'll post it in both and see where I get.

I have two computer images... one of them is an "original" image (a large TIF file). The other one is a transformed version of the original image... it's been rotated, sheared and translated in a software program. I need to do some work on the transformed image, but I need the (x-y) coordinates of each pixel in the original image to finish my calculations.

I know that the image was rotated and sheared with a 3x3 Transformation matrix. If I had the matrix, I could derive the second image from the first (or vice-versa) myself. I don't know exactly how much it was rotated, sheared, or translated, so I can't just derive the matrices from a set of known transformations. What I do have is a set of corresponding points (the corners, et al) in each image, and their corresponding (x,y) coordinates. So here's my dilemma:

Using a set of corresponding transformed points ((x,y) -> (x',y'), three or more of them), can I derive the Transformation matrix that was used to turn one image into the other? If I can derive the matrix, I can solve for the original coordinates of all the pixels (all 18-million of 'em) and get the calculations done that I need to do.

Can anyone help? I'm familiar with linear algebra... just not familiar enough to derive this without a whole lotta head scratching. Anything is appreciated!

  • Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神回复 2024-08-20 05:46:25

不确定您需要手动还是自动

手动

如果指定矩形四个角的变换坐标,则可以导出变换方程:(

x' = c1 * x + c2 * y + c3 * x * y + c4
y' = c5 * x + c6 * y + c7 * x * y + c8

来自 Pierre Wellner 的 与 DigitalDesk 上的纸张交互,第 67 页)

现在您只需求解方程的系数即可。

对于四个点对,可以通过高斯消元法快速求解两组四个联立线性方程,从而找到 c1-8 的值。

最后,您可以将这些方程转换为您想要的 3x3 矩阵。上述方程足够强大,可以进行非线性变换,您可以将其简化为 3x3 仿射剪切矩阵。

但我会坚持使用非线性方程(上面),因为它们可以处理透视变形

自动

相同的方法,但您可以使用边缘检测器与线条检测算法相结合来查找构成矩形的一组 4 条左右的线条。

如果您的图像矩形确实很突出(深色背景上的白色图像),那么您可以使用 OpenCV 的特征检测(请参阅cv::cornerHarris)。

您可以将这些线相交以找到四个角并使用变换方程。

Not sure if you want manual or automatic.

Manual

If you specify the transformed coordinates of the four corners of your rectangle, then you can derive the transformation equations:

x' = c1 * x + c2 * y + c3 * x * y + c4
y' = c5 * x + c6 * y + c7 * x * y + c8

(From Pierre Wellner's Interacting with Paper on the DigitalDesk, page 67)

Now you just have to solve for the coefficients of the equation.

With four point pairs, the two sets of four simultaneous linear equations can be quickly solved by Gaussian Elimination to find the values of c1-8.

Lastly, you can turn those equations into the 3x3 matrices you want. The above equations are powerful enough to do non-linear transformations and you can simplify it into the 3x3 affine shear matrix.

But I would just stick with the nonliner equations (above) since they can handle perspective distortion.

Automatic

Same method, but you can use an edge-detector comboined with a line detection algorithm to find a set of 4-ish lines that makeup a rectangle.

If your image rectangles really stand out (whiteish images on a dark background), then you can use corner detection available from libraries like OpenCV's Feature Detection (see cv::cornerHarris).

You can intersect those lines to find the four corners and use the transformation equation.

稳稳的幸福 2024-08-20 05:46:25

我认为您应该首先提供一个列表,例如 3 个点(对于 6 个未知数)以及变换前后的 X/Y 坐标。

然后,比我更聪明的人应该将其放入一组线性方程中,然后将其输入(例如)Wolfram Alpha 进行求解。

AffineTransform 显示需要如何设置矩阵:

[ x']   [  m00  m01  m02  ] [ x ]   [ m00 x + m01 y + m02 ]
[ y'] = [  m10  m11  m12  ] [ y ] = [ m10 x + m11 y + m12 ]
[ 1 ]   [   0    0    1   ] [ 1 ]   [           1         ]

去除大部分绒毛叶子:

[ x']   [ m00 x + m01 y + m02 ]
[ y'] = [ m10 x + m11 y + m12 ]

然后您只需设置一组 6 x 2 方程,如下所示:(

m00 x + m01 y + m02 - x' = 0
m10 x + m11 y + m12 - y' = 0

对其他 2 个 x/y 之前/之后对重复)

并将它们扔到方程求解器。

I think you should start by providing a list of, say 3 points (for 6 unknowns) with X/Y coordinates before and after transformation.

Then somebody more clever than I should pop that into a set of linear equations and then feed it to (say) Wolfram Alpha for solving.

The top of Java's documentation for AffineTransform shows how the matrix needs to be set up:

[ x']   [  m00  m01  m02  ] [ x ]   [ m00 x + m01 y + m02 ]
[ y'] = [  m10  m11  m12  ] [ y ] = [ m10 x + m11 y + m12 ]
[ 1 ]   [   0    0    1   ] [ 1 ]   [           1         ]

Removing most of the fluff leaves:

[ x']   [ m00 x + m01 y + m02 ]
[ y'] = [ m10 x + m11 y + m12 ]

Then you just set up a set of 6 x 2 equations like this:

m00 x + m01 y + m02 - x' = 0
m10 x + m11 y + m12 - y' = 0

(repeat for 2 other x/y before/after pairs)

and throw them at an equation solver.

站稳脚跟 2024-08-20 05:46:25

您只需要 3 个点即可定义 3x3 变换矩阵。如果你有点 (0,0)、(0,1) 和 (1,0) 并将它们通过矩阵 [abcdef 0 0 1] 进行变换,你将得到 (c,f), (b,e)和(a,d)。

You only need 3 points to define a 3x3 transformation matrix. If you have the points (0,0), (0,1) and (1,0) and transform them by the matrix [a b c d e f 0 0 1], you'll get (c,f), (b,e) and (a,d).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文