How to recreate the math behind photoshop curves

后端 未结 5 627
小蘑菇
小蘑菇 2020-12-23 15:13

Basically, what I want to do is understand how to calculate the values along a \'curve\' as represented here in the photoshop curves box:

5条回答
  •  醉酒成梦
    2020-12-23 16:05

    A Catmull-Rom Spline is used because it's a kind of spline that represents a curve in which you can add control points and refine the curve itself (that is what you do on Photoshop when you click to add a new point), with the particularity to have the curve pass by every control point you specify.

    In any case you just need a function that taken a value (float in 0..1 or int in 0..255 or whatever color space you have) will produce another one.

    float fun(float x) {
      y = /* something */
      return y;
    }
    

    This can be done with whatever kind of function of course. The most basic one is the default one that is an identity function

    float fun(float x) {
      y = x;
      return y;
    }
    

    Any other function can be calculated with curves and it will be ok but more complex to develop, I'd suggest you to start from simple examples like a Bezier curve. In any case the t parameter is used because these are parametric curves, you need to understand some of the mathematical background of curves before digging into development, take a look here.

提交回复
热议问题