CONTEXT
I'm working on an image processing algorithm, which uses pixel lightness values to determine how much the pixel should be darkened.
A small range of lightness values should be "selected" by the function, with a smooth transition to the unselected ones. The desired behaviour is visually described below:
X is the pixel lightness
Y is the multiplier to be applied to the pixel lightness later on
I should be able to control 3 parameters:
- A: Filter center
- B: Some kind of Bandwidth
- C: Gain
WHERE I AM NOW
At first, I've tried using a simple parabola and clipping y values above 1:
$y = B(x-A)^2+(1-C)$
However, the harsh clipped transition adds noise to the final image. I need a smoother transition.
So, I gave it another shot with two very expensive tanh curves, reflected by the filter center:
$y = \left\{ \begin{array}{ll} 1-\Big[tanh(B(x-A)+B')+1\Big](C/2) & \mbox{if } x \leq A \\ 1-\Big[tanh(B(A-x)+B')+1\Big](C/2) & \mbox{if } x > A \\ \end{array} \right.$
The results are better, however since I'll be processing 1080p videos with this algorithm, I don't think calculating tanh for every single pixel is a good thing.
THE FINAL QUESTION
Is there a way to model this behaviour without expensive operations such as tanh?



If a polynomial is suitable, then consider
$$ f(x)=c_0+c_1x+c_2x^2+c_3x^3+c_4x^4 $$
Solving for the $c_n$, using the conditions:
$$ f'(A)=f'(A+B/2)=f'(A-B/2)=f(A+B/2)=0 \quad; \quad f(A)=C $$
Using your notation: $A$ is position of center, $B$ is width, $C$ is the height. This is just for the peak: you need to subtract it from 1 to get the 'upside down version'. The coefficients are
$$ c_0=\frac{C}{B^4}(B^4-8B^2A^2+16A^4) \\ c_1=\frac{16C}{B^4}(B^2A-4A^3) \\ c_2=-\frac{8C}{B^4}(B^2-12A^2) \\ c_3=-\frac{64CA}{B^4} \\ c_4=\frac{16C}{B^4} $$
Here is a plot with $A=1$, $B=0.1$, $C=2$
Of course we are only interested in the graph between $A-B/2 \ < x < \ A+B/2$. It's tangent to the horizontal at the boundary.