使图像变形,使曲线变成直线

发布于 2024-12-06 20:35:49 字数 148 浏览 0 评论 0原文

我有一个图像,上面覆盖有自由形式的曲线(实际上是小线段的列表),我想生成某种图像扭曲,使图像变形,使这些曲线变形为水平直线。

我已经将所有线段点的坐标单独存储,因此不必从图像中提取它们。我正在寻找一种适当的方法来扭曲图像,使这些线条扭曲成直线。

谢谢

I have an image with free-form curved lines (actually lists of small line-segments) overlayed onto it, and I want to generate some kind of image-warp that will deform the image in such a way that these curves are deformed into horizontal straight lines.

I already have the coordinates of all the line-segment points stored separately so they don't have to be extracted from the image. What I'm looking for is an appropriate method of warping the image such that these lines are warped into straight ones.

thanks

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

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

发布评论

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

评论(2

月牙弯弯 2024-12-13 20:35:49

您需要从一个映射公式开始,给定输出坐标将提供输入图像的相应坐标。根据您尝试纠正的失真情况,这可能会变得极其复杂;您的问题没有足够详细地说明问题。例如,图像顶部的曲线与底部的曲线相同,与中间的曲线相同吗?水平距离会根据线的角度压缩吗?让我们假设最简单的情况,水平坐标根本不需要任何校正,垂直坐标只需要基于水平的恒定校正。这里,x,y 是输入图像上的坐标,x',y' 是输出图像上的坐标,f()是绘制的线段与理想直线之间的差异。

x = x'
y = y' + f(x')

现在,您只需遍历输出图像的所有像素,计算输入图像中的对应点,然后复制像素即可。这里的问题是,您的公式可能会给出位于输入像素之间的点,例如 y=4.37。在这种情况下,您需要进行插值以从输入中获取中间值;图像的插值方法有很多种,我不会在这里尝试深入讨论。最简单的是“最近邻居”,您只需将坐标四舍五入到最接近的整数即可。

You need to start out with a mapping formula that given an output coordinate will provide the corresponding coordinate from the input image. Depending on the distortion you're trying to correct for, this can get exceedingly complex; your question doesn't specify the problem in enough detail. For example, are the curves at the top of the image the same as the curves on the bottom and the same as those in the middle? Do horizontal distances compress based on the angle of the line? Let's assume the simplest case where the horizontal coordinate doesn't need any correction at all, and the vertical simply needs a constant correction based on the horizontal. Here x,y are the coordinates on the input image, x',y' are the coordinates on the output image, and f() is the difference between the drawn line segment and your ideal straight line.

x = x'
y = y' + f(x')

Now you simply go through all the pixels of your output image, calculate the corresponding point in the input image, and copy the pixel. The wrinkle here is that your formula is likely to give you points that lie between input pixels, such as y=4.37. In that case you'll need to interpolate to get an intermediate value from the input; there are many interpolation methods for images and I won't try to get into that here. The simplest would be "nearest neighbor", where you simply round the coordinate to the nearest integer.

沉睡月亮 2024-12-13 20:35:49

您可以使用与此处开发的方法类似的方法:
http://www-ui.is.su-tokyo .ac.jp/~takeo/research/rigid/

您要做的就是定义一个覆盖源图像的 MxN 控制点网格。
然后,您需要确定如何修改每个控制点,以便最终图像最小化某些能量函数(最小曲率或类似的东西)。

最终图像是由控制点确定的线性扭曲(将其视为 2D 网格,其纹理是源图像,并且要修改其顶点位置)。

只要您的能量函数可以使用线性方程表示,您就可以使用线性方程求解器全局解决您的问题(弄清楚将每个控制点发送到哪里)。

您使用周围网格点的双线性插值权重来表达每个源点(位于曲线上的源点),然后通过为这些点编写方程来表达对目标的限制。

解完这些线性方程后,您最终会得到目标网格点,然后您只需使用新顶点的位置渲染 2D 网格即可。

You can use methods similar to those developed here:
http://www-ui.is.s.u-tokyo.ac.jp/~takeo/research/rigid/

What you do, is you define an MxN grid of control points which covers your source image.
You then need to determine how to modify each of your control points so that the final image will minimize some energy function (minimum curvature or something of this sort).

The final image is a linear warp determined by your control points (think of it as a 2D mesh whose texture is your source image and whose vertices' positions you're about to modify).

As long as your energy function can be expressed using linear equations, you can globally solve your problem (figuring out where to send each control point) using linear equations solver.

You express each of your source points (those which lie on your curved lines) using bi-linear interpolation weights of their surrounding grid points, then you express your restriction on the target by writing equations for these points.

After solving these linear equations you end up with destination grid points, then you just render your 2D mesh with the new vertices' positions.

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