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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)