3
$\begingroup$

I am looking for the way to "quite easily" express particular curves using functional equations.

s-curves

What's important (supposing the chart's size is 1x1 - actually it doesn't matter in the final result):

  • obviously the shape - as shown in the picture;
  • there should be exactly three solutions to f(x) = x:
    x=0, x close to or equal 0.5 and x=1;
  • (0.5,0.5) should be the point of intersection with y = x;
  • it would be really nice, if both of the arcs are scalable - as shown in the left example (the lower arc is more significant than the upper one).

I've done some research, but nothing seemed to match my needs; I tried trigonometric and sigmoid functions too, they turned out to be quite close to what I want. I'd be grateful for any hints or even solutions.

P.S. The question was originally asked at stackoverflow and I was suggested to look for help here. Some answers involved splines, cumulative distribution functions or the logistic equation. Is that the way to go?

  • 0
    Presumably you also want the function to never go outside the range $[0,1]$, right?2012-07-15
  • 0
    That's right. It shouldn't go outside the range [0,1] for any x from [0,1].2012-07-15
  • 0
    The graph on the left suggests that you don't insist in having a tangent line at 0.5 (the curve appears to have a corner there). If so, then you essentially want two functions: one of [0,0.5] and.another in [0.5,1]. The boundary values are given, and apparently the first function should be convex while the other concave. Looks like a job for two parabolas.2012-07-15
  • 0
    It would be best if you could elaborate on how the things you've looked up so far *didn't* match your needs. Your problem as given is underspecified (there are lots of functions that will do the job), and it would help to get an idea of what "soft" or "aesthetic" features you're looking for to pick the best one.2012-07-15
  • 0
    @Leonid the curves should be used for image processing so I guess it would be better to avoid corners? Anyway, thanks for suggestion, that's pretty simple idea.2012-07-15
  • 0
    @Rahul well, I don't have any specified needs except those listed above. I'm looking for the simplest possible idea (the 2 last options I mentioned don't sound friendly to me) - to express the function and to calculate its values. Its application involves image processing; not sure yet how I will implement it - I consider storing precalculated values and calculating them on the fly as well.2012-07-15
  • 0
    If you want continuous derivative of 1st order, it is natural to use cubic spline interpolation - http://en.wikipedia.org/wiki/Spline_interpolation2012-07-15
  • 0
    Thanks again for that suggestion. However, will it overcome the "going out of range" and "not soft behavior" problems, which are being considered in Rahul's answer below?2012-07-15

2 Answers 2

3

For what it's worth, the interpolating polynomial through the points $(0,0), \big(\!\frac14,a\big)$, $\big(\!\frac12,\frac12\!\big)$, $\big(\!\frac34,b\big)$, and $(1,1)$ is $$p(x) = \left(-7+16 a+\frac{16 b}{3}\right) x+\left(\frac{136}{3}-\frac{208 a}{3}-\frac{112 b}{3}\right) x^2+\left(-80+96 a+\frac{224 b}{3}\right) x^3+\left(\frac{128}{3}-\frac{128 a}{3}-\frac{128 b}{3}\right) x^4.$$ However, it overshoots the range $[0,1]$ on similar input to the first image. Below I picked $a = \frac18$ and $b = \frac{13}{16}$.

enter image description here

  • 1
    You might also consider the Hermite interpolant $$p(x)=(2 b-2 a) x^4+(5 a-3 b-2) x^3+(b-4 a+3) x^2+a x$$ The polynomial passes through those three points and has the property that $p^\prime(0)=a$ and $p^\prime(1)=b$.2012-07-15
  • 0
    Thanks, the idea seems to be nice, although the so called "overshooting" is a major problem. I want the curve to behave as it behaves in Curves tool in image processing software (Gimp, Photoshop etc.) - generally speaking it behaves in a far softer way. Here is another example (with x and y in [0,255]), on a verge of acceptance: http://ubuntuone.com/2GtSMuciatWC99P1EhsMWS - note that the curve leans gently to the edges.2012-07-15
  • 0
    And thanks for the Hermite suggestions.2012-07-15
1

Have you tried polynomial interpolation? It seems that for 'well-behaved' graphs like the ones you are looking for (curves for image processing?), it could work just fine.

At the bottom of this page you can find an applet demonstrating it. There is a potential problem with the interpolated degree 4 curve possibly becoming negative though. I'll let you know once I have worked out a better way to do this.

EDIT: The problem associated with those unwanted 'spikes' or oscillations is called Runge's phenomenon . I would guess that image manipulation programs like Photoshop actually use Spline interpolation to find the curves.

  • 0
    Yes, I'm looking for curves for image processing. Thanks for the suggestion, I will take a closer look at it!2012-07-15
  • 0
    Just edited my answer with some extra info and another possible method. Hope this helps!2012-07-15