How to recreate the math behind photoshop curves

后端 未结 5 616
小蘑菇
小蘑菇 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 15:54

    Photoshop uses an interpolating cubic spline for the curve, as explored on a separate Math StackExchange thread.

    0 讨论(0)
  • 2020-12-23 16:01

    I'm not familiar with C-R, but if it's like beziers, than the T parameter varies from 0 at one endpoint of a curve section to one at the other end point. It's how you "step along" the curve. So you can't just plug an x value you in. You can either sample a long at some arbitrary interval or you can use some sort of goal seeking algorithm to approach a given x value to whatever amount of precision you deem necessary.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-23 16:12

    Here's a link to a vbscript that appears to implement the cubic-spline curves photoshop uses.

    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=68577&lngWId=-1

    0 讨论(0)
  • 2020-12-23 16:13

    This code appears to match Photoshop's curves exactly (not my code): http://www.developpez.net/forums/d331608-3/autres-langages/algorithmes/contribuez/image-interpolation-spline-cubique/#post3513925

    0 讨论(0)
提交回复
热议问题