1

I was editing an image by increasing the contrast. For this I used the formula $(\tanh(\mathtt{CONTRAST\_FACTOR}*(x-0.5))+1)/2$ This formula has limits at 0 and 1, with y=0.5 at x=0.5.

The problem for my situation is that y is only limited between 0 and 1, but I want a formula that has the following properties:

  • the curve is continuous (at least between 0 and 1)
  • the line goes through $(0,0)$, $(0.5,0.5)$ and $(1,1)$
  • I want a constant (like contrast factor above) that can influence the slope around $(0.5,0.5)$, which basically determine the curviness.

Does anyone know a formula like that?

  • Extending the approach you already have: Use a scaled, shifted $\tanh^{-1}$ to map $(0,1)$ to $(-\infty,\infty)$, multiply by the contrast factor, then apply $\tanh$ as before. See e.g. https://math.stackexchange.com/a/898792/856 –  Dec 21 '18 at 05:26

2 Answers2

2

Maybe a cubic Bézier curve: $$ y=3hx(1-x)^2 +3(1-h)x^2(1-x) + x^3 $$

This is just the Bézier curve with coefficients $0,h,1-h,1$. These are then combined with the cubic Bernstein polynomials $(1-x)^3$, $3x(1-x)^2$, $3x^2(1-x)$, $x^3$ to produce the formula above.

You can vary $h$ between $0$ and $1$ to adjust the shape of the curve. I suspect that you might want the curve to be monotone increasing, which will happen if $h$ lies between $0$ and $\tfrac13$.

bubba
  • 43,483
  • 3
  • 61
  • 122
  • Could you explain your formula a bit like the other answer did (more than just how to use it I mean) – coolcat007 Dec 21 '18 at 15:53
  • Standard Bézier curve stuff. The formula gives the real-valued Bézier curve with coefficients $0, h,1-h,1$. These coefficients are combined with the cubic Bernstein polynomials to give the formula. – bubba Dec 23 '18 at 12:23
1

How about a simple polynomial?

Let $s$ be the slope at $(0.5,0.5)$. You desire $f'(0.5)=s$, $f(k)=k, k\in\{0,0.5,1\}$.

A cubic seems to fit:

$$f(x)=ax^3+bx^2+cx+d$$ $$f'(x)=3ax^2 + 2bx + c$$ Plugging in each of the points, we have a system of equations: $$d=0$$ $$\dfrac{a}{8}+\dfrac{b}{4}+\dfrac{c}{2}=\dfrac{1}{2}$$ $$a+b+c=1$$ $$\dfrac{3a}{4}+b+c=s$$

which has solution:

$$a=4-4s, \ b=-3(2-2s), \ c=3-2s, \ d=0$$

So the desired cubic is:

$$f(x)=(4-4s)x^3-3(2-2s)x^2+(3-2s)x$$

See HERE for an animation over different values of $s$.

David P
  • 12,320
  • I think that I am looking for the inverse of this formula, because I need s to be greater than 1 while still having a function that strictly increases between x of 0 and 1 – coolcat007 Dec 21 '18 at 15:58
  • Check $1\le s\le 1.5$ It switches concavity and keeps monotonicity on your interval – David P Dec 21 '18 at 19:08
  • lets see... can you extend the formula so that the slope at (0,0) and (1,1) is always 0? – coolcat007 Dec 21 '18 at 20:50
  • That would require a higher-degree polynomial for manipulation purposes at least (this is only true for $s=1.5$ with this model), try degree five. Introduce that $f'(0)=0,f'(1)=0$ and solve the larger system – David P Dec 21 '18 at 21:27