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?
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$.