Pages: [1]   Go Down

### AuthorTopic: HELP: Equation for a Contrast Curve (with precise location of the turning point)  (Read 23105 times)

#### Guillermo Luijk

• Sr. Member
• Offline
• Posts: 1843
##### HELP: Equation for a Contrast Curve (with precise location of the turning point)
« on: March 19, 2011, 11:15:31 am »

Hi all, I am doing some tests about local/global contrast algorithms and need a simple equation to define an arbitrary S-shaped contrast curve. It's simple if the turning point is assumed to be (0.5, 0.5), but couldn't find a straight equation if the turning point has to be arbitrarily set.

These are the typical contrast curves I achieved for turning point in the middle (0.5, 0.5):

And the simple equations follow this rule:

y = x^2*2 for x<=0.5
y = 1-(1-x)^2*2 for x>0.5

I would like to be able to allocate the turning point to any (x,y) position and still have a smooth S-shaped curve where the slope is continuous on both sides of the turning point. I would like to keep the equation as simple and straightforward as possible, avoiding the use of splines or any other more complex math.

Any ideas? I tried to google but found nothing yet.

Regards

PS: what I want to try is to enhance local contrast at the same time as reducing global contrast (something typical in HDR imaging), using locally defined curves. The goal is to apply a custom contrast curve to every pixel, with its turning point calculated according to the average luminance of the pixel's neighbourhood:

« Last Edit: March 20, 2011, 12:22:41 am by Guillermo Luijk »
Logged

#### joofa

• Sr. Member
• Offline
• Posts: 544
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning po
« Reply #1 on: March 19, 2011, 11:28:55 am »

Hi Guillermo,

Would a sigmoid function work?

Sincerely,

Joofa
Logged
Joofa
http://www.djjoofa.com

#### Guillermo Luijk

• Sr. Member
• Offline
• Posts: 1843
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #2 on: March 19, 2011, 11:31:23 am »

Anything with a smooth S-shape and where the turning point can be freely located, but the sigmoid doesn't guarantee (0,0) and (1,1), right?

« Last Edit: March 19, 2011, 11:34:08 am by Guillermo Luijk »
Logged

#### crames

• Full Member
• Offline
• Posts: 210
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #3 on: March 19, 2011, 11:59:08 am »

Hi Guillermo,

Have you searched "sigmoid function" (or sigmoidal curve)? You will find a lot of different formulas, but I'm not sure if any are simple enough for your purposes.

edit: Joofa beat me to it!
Logged
Cliff

• Jr. Member
• Offline
• Posts: 87
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #4 on: March 19, 2011, 12:30:37 pm »

Hi,

Do you always want 0,0 and 1,1 on your curve? How many other points do you want to specify--just one?
Logged

#### Guillermo Luijk

• Sr. Member
• Offline
• Posts: 1843
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #5 on: March 19, 2011, 12:50:13 pm »

Do you always want 0,0 and 1,1 on your curve? How many other points do you want to specify--just one?

Ideally it would be a curve with just 3 parameters:
* X location of turning point
* Y location of turning point
* Intensity of the S shape (that can determine both an S shape or inverted S shape)

And must achieve:
* Include (0,0) and (1,1)
* Be smooth (no gaps in the first derivative, even at the turning point)

So it's basically a 3 point curve, with S shape.

#### Christoph C. Feldhaim

• Sr. Member
• Offline
• Posts: 2509
• There is no rule! No - wait ...
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #6 on: March 19, 2011, 04:17:06 pm »

You might want to have a look at Bézier Spline Curves.

#### ejmartin

• Sr. Member
• Offline
• Posts: 575
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #7 on: March 19, 2011, 04:56:53 pm »

Hi all, I am doing some tests about local/global contrast algorithms and need a simple equation to define an arbitrary S-shaped contrast curve. It's simple if the turning point is assumed to be (0.5, 0.5), but couldn't find a straight equation if the turning point has to be arbitrarily set.

These are the typical contrast curves I achieved for turning point in the middle (0.5, 0.5):

And the simple equations follow this rule:

y = x^2*2 for x<=0.5
y = 1-(1-x)^2*2 for x>0.5

I would like to be able to allocate the turning point to any (x,y) position and still have a smooth S-shaped curve where the slope is continuous on both sides of the turning point. If would like to keep the equation as simple and straightforward as possible, avoiding the use of splines or any other more complex math.

Your curve is a spline -- a piecewise polynomial curve with conditions of continuity of the curve and its first derivative at the segment boundaries.

Just for fun, take the first curve and scale it:

y = a*(x/a)^2

This is a curve which reaches y=a at x=a, and has slope 2 at that point; and slope zero at x=0.  If we take your second curve and scale it by (1-a):

(1-y) =  (1-a)*((1-x)/(1-a))^2

this is a curve which reaches 1-y=1-a at 1-x=1-a, or in other words y=a at x=a; it has slope 2 at that point; and slope zero at x=1, where also y=1.  So we have a sigmoidal curve with slope zero at x=0 and x=1, and slope 2 at x=a where the curve crosses the straight line x=y.

Now we can add a control parameter: Take the above curve, call it f(x); now form the curve

y = (1-s)*x + s*f(x)

This is a curve that has slope (1-s) at x=0 and x=1; and slope (1-s)+2*s=1+s at x=a.  Thus by dialing s between 0 and 1, the slope at the neutral point x=a (where y=a of course) is dialed between 1 and 2; the contrast is gradually increased, and the curve is monotonic.  For contrast decrease, you can either allow s to be negative, or if you want the effect to be symmetric about s=0, you want to interchange the roles of y and x in this regime.
« Last Edit: March 19, 2011, 05:08:48 pm by ejmartin »
Logged
emil

#### Guillermo Luijk

• Sr. Member
• Offline
• Posts: 1843
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #8 on: March 19, 2011, 08:44:26 pm »

Perfect solution Emil, simple and elegant. Just needs an extra powering to shift the turning point from (a,a) to (a,b):

y = [ (1-s)*x + s*a*(x/a)^E ] ^ ( log(b)/log(a) )

Parameters:
• (a,b): turning point
• s: slope at ends
• E: contrast strength

Thanks a lot and thanks to all who helped.

Regards
« Last Edit: March 19, 2011, 11:54:34 pm by Guillermo Luijk »
Logged

#### kirkt

• Sr. Member
• Offline
• Posts: 585
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #9 on: March 19, 2011, 08:52:17 pm »

Love it. This should be fun.

Kirk
Logged

#### George Machen

• Newbie
• Offline
• Posts: 14
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #10 on: March 20, 2011, 12:42:12 pm »

turning point — "point of inflection"
Logged

#### Guillermo Luijk

• Sr. Member
• Offline
• Posts: 1843
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #11 on: March 20, 2011, 02:42:47 pm »

turning point — "point of inflection"

It's fun because in Spanish it's also called 'punto de inflexión', but I googled it and found that the most appropiate translation could be 'turning point'.

I got the very first result with quite strong parameters. I have to play more with their values to optimise halos, but the result is according to what I expected:

Regards

#### ejmartin

• Sr. Member
• Offline
• Posts: 575
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #12 on: March 21, 2011, 09:04:42 am »

I'm a little confused about the method.  If one does USM with high radius, low amount, one is effectively taking the difference with the neighborhood average and amplifying it, then adding that back to the neighborhood average.  Your approach doesn't look like it differs much from HR-LA USM except that the amount of amplification (aka contrast) itself depends on the neighborhood average, and a tone curve is being applied to the neighborhood average for tonal compression (S/H tool).  What is the advantage of having an entire curve, if one is only adjusting the value of the pixel relative to its neighborhood average?  Perhaps I am just misinterpreting your figure:

« Last Edit: March 21, 2011, 10:42:01 am by ejmartin »
Logged
emil

#### PierreVandevenne

• Sr. Member
• Offline
• Posts: 512
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #13 on: March 21, 2011, 10:12:22 am »

If the discussion runs its course, we'll be hitting "a trous" wavelet functions before the end of the year...
Logged

#### Guillermo Luijk

• Sr. Member
• Offline
• Posts: 1843
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #14 on: March 25, 2011, 05:04:34 pm »

What is the advantage of having an entire curve, if one is only adjusting the value of the pixel relative to its neighborhood average?  Perhaps I am just misinterpreting your figure:

A different curve is applied to every pixel according to the neighbourhood average, but that curve is chosen from a limited set of pre-calculated curves. The curve chosen is that which has the inflection point in the pixel's neighbourhood average luminance.

This anim shows 16 of the 256 curves calculated for increasing of parameter E (contrast slope at inflection point):

The result is similar to PS's USM + S/H as you say.

Now with the coloured image, strong parameters provide that HDR'ish look:

Regards
« Last Edit: March 25, 2011, 05:43:44 pm by Guillermo Luijk »
Logged

#### Carter Lee

• Newbie
• Offline
• Posts: 1
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #15 on: January 01, 2015, 11:36:18 pm »

Hi. Sir.
I've just tried implement with your equation. but it doesn't work.

x   a   b   s   E      Y
0   0.3   0.4   1   1      0
0.1   0.3   0.4   1   1      0.173358043
0.2   0.3   0.4   1   1      0.29379519
0.3   0.3   0.4   1   1      0.4
0.4   0.3   0.4   1   1      0.497903715
0.5   0.3   0.4   1   1      0.590064265
0.6   0.3   0.4   1   1      0.677892263
0.7   0.3   0.4   1   1      0.762273695
0.8   0.3   0.4   1   1      0.843812691
0.9   0.3   0.4   1   1      0.922945352
1   0.3   0.4   1   1      1

Logged

#### Guillermo Luijk

• Sr. Member
• Offline
• Posts: 1843
##### Re:
« Reply #16 on: January 02, 2015, 01:01:49 pm »

I confirm the equation. I used it to generate the sample plots.

#### Rory

• Sr. Member
• Offline
• Posts: 528
##### Re: HELP: Equation for a Contrast Curve (with precise location of the turning point)
« Reply #17 on: January 04, 2015, 02:29:36 pm »

I am interested too.  What have I done wrong?

« Last Edit: January 04, 2015, 07:40:08 pm by Rory »
Logged
[url=http://www.flickr.com/photos/roryhi

#### Guillermo Luijk

• Sr. Member
• Offline
• Posts: 1843
##### Re:
« Reply #18 on: January 05, 2015, 01:58:21 am »

"And the simple equations follow this rule:

y = x^2*2 for x<=0.5
y = 1-(1-x)^2*2 for x>0.5"

I think you are missing it's a function defined in two stages. Please read the entire thread.
« Last Edit: January 05, 2015, 12:39:36 pm by Guillermo Luijk »
Logged
Pages: [1]   Go Up