How to make a log gradient?

RB
Posted By
Rob_Blaser
Nov 17, 2003
Views
1775
Replies
16
Status
Closed
I’ve just been trying to make a log (logarithmic) gradient instead of a linear gradient. This might be easy, but I have searched and tried with no luck. Any help would be greatly appreciated.

Thanks

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

Y
YrbkMgr
Nov 17, 2003
What does a Log Gradient look like. Maybe if you post an example on the web and tell us the link, some folks can chime in with how to accomplish it.

Peace,
Tony
GH
Grass_Hopper
Nov 17, 2003
I was wondering if he meant a sine wave?
Y
YrbkMgr
Nov 17, 2003
Could mean anything I suppose – I used Log curves in math and science to create a linear curve for calibration of equipment/standards, etc. That is to say, that my experience was that using log was a way to create something linear. So, I’m just as stumped.
GH
Gernot_Hoffmann
Nov 17, 2003
A log gradient is a log gradient and not a sine wave.

For example in x-direction x=0 to x=1:

luminance =Ln (1+x) / Ln(2)

This delivers luminance=0 for x=0 and luminance=1 for x=1 and between we have a function which looks like
luminance = x^0.5 or so.

"Ln" is the logarithmus naturalis (based on the Euler number e).

Sorry for bothering the folks with mathematics – it cannot be done by PhS accurately.

Best regards –Gernot Hoffmann
GH
Grass_Hopper
Nov 17, 2003
Thanks for the lesson Gernot 🙂

But what does he want to do with such a gradient? Is he trying to achieve, for instance, a black -> white gradient in a log gradient fashion?
RB
Rob_Blaser
Nov 17, 2003
Yes, as Gernot mentioned, a log function is very different than a linear one. A linear function–or gradient for this matter–is a straight line. So the gradient transistions from say black to white evenly. However a log gradient would go from black to white much differently. I’ll try to illustrate…forgive the crude manner…
Let’s say you want a gradient from black to white going from A to B spatially. Now let’s say that the colors from black to white are represented by the numbers 1-10, 1 being black and 10 being white.
A linear gradient would look somewhat like the following…

A………………………………………..B
1…2…3…4…5…6…7…8…9…10

Giving a nice even transition from black to white. However a log gradient would look somewhat like the following:

A…………………………………………B
123.4..5…6….7…..8……9…….10

Where the rate of transistion is much faster at point A and the rate of transitin gets slower as you approach point B.

Hope this helps explain…

* *EDIT: My A B thing didn’t work with spaces so I put periods in there to keep the correct spacing. Sorry
GH
Gernot_Hoffmann
Nov 17, 2003
Grass Hopper,

I regret if my post should sound like a "lesson".

Occasionally some questions are written in mathematical terms. Then I feel obliged to respond similarly.

Best regards –Gernot Hoffmann
JS
John_Slate
Nov 17, 2003
Gradients made with the gradient tool are not exactly linear but are a bit more gradual at both ends.

Chris Cox "SQUARE gradiant tool- where is it??????" 1/25/03 4:24pm </cgi-bin/webx?13/21>

However they are not exactly logarithmic either. I would think applying a curve would be the answer, though the exact curve is beyond me.
CC
Chris_Cox
Nov 18, 2003
John – UNLESS you change the smoothness to zero, then they are linear.
GH
Grass_Hopper
Nov 18, 2003
Gernot,

I regret if my post should sound like a "lesson". Please, no need to apologize! I really do learn some things from your mathematics, although I will confess many times it is over my head! 😉 I am a firm believer in the notion that there is *always* more to learn 🙂 I am also pleased that you share your knowledge with us.

kind regards,
grasshopper
GH
Gernot_Hoffmann
Nov 18, 2003
Thanks, then I can continue:

Rob,

a gradient from black to white is modified by Curves,
bottom left black, top right white, by a banana upwards
deformation:

x……..255*x……….Ln(x+1)/Ln(2)……..255*Ln(x+1)/Ln( 2)

0.0……….0………….0.0……………………….0
0.25….. 64………….0.322………………….82
0.50….128………….0.585………………..149
0.75….191………….0.807………………..206
1.0……255………….1.0……………………255

The value in column 2 is the input, the value in column 4 is the output for the modified curve.

One should be aware that the indicated values for the
straight line curve (without modification) are already Gamma- pre-distorted: in the middle of the gradient pattern we find c = 255*(0.5)^(1/2.2) = 255*0.5^0.4545 = 186 instead of 127.5 .

It would me more accurate to calculate the new values in this order (log in linear light space):

Given input x
y=(x/255)^2.2
z=Ln(y+1)/Ln(2)
output=255*z^(0.4545)

Best regards –Gernot Hoffmann
S
Stroker
Nov 18, 2003
Too add to the math flying around, you can do it with an AMP file if you have some programming savvy.

See: AMP < http://w3.chrlmi.cablespeed.com/~halmich/tech-slop/amp/index .shtml>.

Once you have your AMP file, lay down your gradient with Smoothness: 0%, hit Image > Adjust Curves (ctrl + m), and load the custom AMP.
S
Stroker
Nov 18, 2003
Out of curiosity, I opened up my old Power Basic and plugged in Gernot’s formulas:

open logtest.amp for output as #1

for x=0 to 255

y=(x/255)^2.2
z=log(y+1)/log(2)
o=int(255*z^(0.4545))

print #1,chr$(o);

next i

close #1

The resulting file, logtest.amp, was just a tad away from being linear. Not sure if thats the way its suppossed to be, or if I messed something up.

See for yourself: logtest.amp <http://www.playfiddlelearn.com/stuff/logtest.amp> – right click save as
It’s one channel, so either in an alpha or in a greyscale.
JS
John_Slate
Nov 18, 2003
How about this?

In 0 / Out 0

In 214 / Out 177

In 232 / Out 197

In 280 / Out 236

In 255 / Out 255
RB
Rob_Blaser
Nov 18, 2003
Stroker,

So is using the AMP file the only way to get this to work? From the replies I’ve gotten, I assume there is no easy tool/setting already in photoshop that allows this type of gradient. I’m interested in your amp file method though and I think that i’ll give it a try. Hope it works.

Any other suggestions/hints are still VERY welcome! Thanks.

BTW..I’m actually kind of surprised that this type of gradient isn’t a more common thing…
CC
Chris_Cox
Nov 18, 2003
Rob – most users need visually designed gradients or simple linear gradients.

We haven’t had any demand for logarithmic gradients except from programmers who already knew how to generate them on their own….

Must-have mockup pack for every graphic designer 🔥🔥🔥

Easy-to-use drag-n-drop Photoshop scene creator with more than 2800 items.

Related Discussion Topics

Nice and short text about related topics in discussion sections