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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题