dongwu1410
2014-01-08 22:23
浏览 24
已采纳

确定给定y(输出)值数组的贝塞尔控制点

After having much trial and errors and failures, i decide to ask the question. Supposing that i have an array of red green and blue values as in here : http://pastebin.com/FatLy5FW and i also have written a function to generate a cubic Bezier curve and use it in image manipulation like color curves in gimp or other image editing software's. http://pastebin.com/hAxaYYGJ

How do i determine and set the control points, so that the output of the array of points generated by the bezier curve has same values as that of the values in the array in the former paste.

图片转代码服务由CSDN问答提供 功能建议

经过多次试验,错误和失败之后,我决定提问。 假设我有一个数组 红色绿色和蓝色值如下所示: http://pastebin.com/FatLy5FW 我也写了一个 用于生成三次贝塞尔曲线并在图像处理中使用它,如gimp或其他图像编辑软件中的颜色曲线。 http:/ /pastebin.com/hAxaYYGJ

如何确定和设置控制点,以便贝塞尔曲线生成的点阵列的输出具有相同的值 前粘贴中数组中的值。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanhuiuw12555 2014-01-09 00:41
    已采纳

    TL;DR Check out a better answer here: Algorithm for deriving control points of a bezier curve from points along that curve?

    First, use the excellent search function on stackoverflow to find all questions that are similar to your problem. Like this: https://stackoverflow.com/search?q=fit+points+to+bezier+curve

    Now I didn't see that until I had written a great wall of text. So I'm gonna share it, with the caveat that ultimately, there may be a simpler (and tested) solution among the search results.

    A quadratic Bezier curve is defined by four control points. The mathematical notation (from wikipedia) is:

    B(t) = (1-t)^3*P0 + 3(1-t)^2*t*P1 + 3(1-t)*t^2*P2 + t^3*P3
    

    The line is guaranteed to go through the end points P0 and P3, but not P1 and P2. The equation should hold for every pixel on the curve. Each pixel has an x and a y coordinate. Select a pixel you know is on the curve - that's B(t). This translates to two equations, one for each coordinate. The unknowns are t, P1-x, P1-y, P2-x and P2-y since the control points have two coordinates each; a total of 5. If you only pick one point on the curve, you get 2 equations with 5 unknowns. But if we add a point, we get another t and end up with 4 equations and 6 unknowns. Add 2 more to get 8 equations and 8 unknowns. Since it's a linear equation system it can be solved using Gauss elimination. Stack overflow has answered questions about Gauss elimination so I suggest you implement one of those solutions, this one for example: Logic error for Gauss elimination

    There are a number of pitfalls you need to watch out for:

    • Either use integers or floating-point numbers, consequently. Since the solution is going to be in integers (integer pixel values for the control points) it might be possible to use integers.
    • Don't assume that the pixels fit exactly to the curve, they may be up to 0.5 pixels away in either direction. This affects the accuracy of the answer. You can either do research to make sure it's within acceptable limits for your purposes, or you can do the calculation multiple times with randomly chosen points and select the points that fit the best.
    • If you do use a floating-point algorithm, beware of rounding errors. Floating-point 0.5 for example may not be stored exactly which could lead to 2*0.5 == 1 being false and other crazy stuff.
    • Take care to select good points. Ideally you'd want the pixels you pick evenly spaced on the curve. Check if it makes a difference if the pixels are clumped together instead of spaced out.

    Update: it's actually not a linear equation system so my approach won't work. Check out the answer linked at the top instead.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题