Curve between 0 and 1 for contrast filtering

698 Views Asked by At

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?

2

There are 2 best solutions below

4
On BEST ANSWER

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

2
On

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