0

I found this function somewhere, quite a while ago. I do not exactly know what it is doing. I use it to manipulate a simplex noise output (with greyscale values between 0 and 255), but would like to understand it better.

int ExponentFilter(int value, int cover, double sharpness)
{
    int c = value - (255 - cover);
    if(c < 0)
        c = 0;
    return 255 - ((std::pow(sharpness,c)) * 255);
}

I use it like:

ExponentFilter(n,140,0.98f)

Where n is my value between 0 and 255.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
NeomerArcana
  • 1,978
  • 3
  • 23
  • 50
  • 4
    Have you tried running it with a variety of test data to observe its behaviour? – Sean Nov 25 '13 at 10:08
  • 3
    Well - you've got the function, just plot it. – Hulk Nov 25 '13 at 10:20
  • @Sean thanks for your answer. Yes, I have; as I said I've been using it on greyscale textures generated from simplex noise, so I have an idea of what it's doing. However, I don't understand if the 0 and 255 are hardcoded for a reason or if they could potentially be variables. I don't understand exactly what this function _is_, is "Exponent Filter" the correct name for it? – NeomerArcana Nov 25 '13 at 10:36
  • @Hulk thanks for taking the time to answer. Math isn't my strong-suit. How do I plot a function, and more importantly, what would doing this tell me? – NeomerArcana Nov 25 '13 at 10:37
  • Well, you could, for example, just over a sweep over your 255 input values (just a for-loop), store output the results, drop them in a column of a table calculation program (eg. Excel) and create a graph. Then you'll see on a glance what it does for each input. – Hulk Nov 25 '13 at 10:47

1 Answers1

2

cover is how "shielded" the signal is from being totally cut off. cover 140 means that the 140 highest (brightest) values (116-255) can result in output > 0.

sharpness describes how fast the light fades. 0,98 means that the light fades about twice as fast, but the fading effect is not linear, it is reduced for darker areas.

I would expect this filter to darken and sharpen overexposed images.

Exponentfilter is a fitting name, since the sharpness function uses exponents (pow is the exponent function).

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
  • Cheers, this is exactly what I needed to know. Are you able to provide any resources or where I can learn about graphical filters or maybe some examples of different ones? – NeomerArcana Nov 25 '13 at 12:01