Pages: [1]   Go Down

Author Topic: HELP: Equation for a Contrast Curve (with precise location of the turning point)  (Read 25715 times)

Guillermo Luijk

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 2005
    • http://www.guillermoluijk.com

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 Offline
  • Posts: 544

Hi Guillermo,

Would a sigmoid function work?

Sincerely,

Joofa
Logged
Joofa
http://www.djjoofa.com
Download Photoshop and After Effects plugins

Guillermo Luijk

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 2005
    • http://www.guillermoluijk.com

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 Offline
  • Posts: 210
    • http://sites.google.com/site/clifframes/

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

Brad Smith

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 97

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 Offline
  • Posts: 2005
    • http://www.guillermoluijk.com

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 Offline
  • Posts: 2509
  • There is no rule! No - wait ...

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

ejmartin

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 575

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 Offline
  • Posts: 2005
    • http://www.guillermoluijk.com

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 Offline
  • Posts: 604

Love it. This should be fun.

Kirk
Logged

George Machen

  • Newbie
  • *
  • Offline Offline
  • Posts: 14

turning point — "point of inflection"
Logged

Guillermo Luijk

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 2005
    • http://www.guillermoluijk.com

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 Offline
  • Posts: 575

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 Offline
  • Posts: 512
    • http://www.datarescue.com/life

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 Offline
  • Posts: 2005
    • http://www.guillermoluijk.com

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 Offline
  • Posts: 1

Hi. Sir.
I've just tried implement with your equation. but it doesn't work.
I'm not sure about this so If you can would you please let me know what exactly you did?

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 Offline
  • Posts: 2005
    • http://www.guillermoluijk.com
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 Offline
  • Posts: 528
    • Recent images

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 Offline
  • Posts: 2005
    • http://www.guillermoluijk.com
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