1

In Photoshop, there are gradient options like "perceptual", instead of only the default gradient like in Illustrator. In Illustrator, I believe gradients are not created based on a perceptual interpolation model.

How do you make perceptual gradients in Illustrator, within a hue and also across multiple colors? Is there any mathematical formula for how to calculate that? Preferably, in both RGB and CMYK color models.

5
  • 1
    Hi. There's no such option in Illustrator. If you need to match a Photoshop perceptual gradient in Illustrator, then you could just use more stops, sampling from the Photoshop gradient. The more stops you add, the more accurate it will be. see example
    – Billy Kerr
    Feb 18 at 9:53
  • Hi, thanks for the reply. Just to clarify - the middle stops, how are they calculated? For example, in cmyk mode, in the 5 stop example, if red is 100 M 100 Y and blue is 100 C and 100 M, what would be CMYK values of the three other stops?
    –  adel357
    Feb 18 at 16:41
  • I didn't calculate them, I sampled them from the Photoshop gradient. You can place a CMYK image in Illustrator and sample CMYK colours too.
    – Billy Kerr
    Feb 18 at 18:23
  • On the Adobe site, they say this about the perceptual gradient in Photoshop: "This method interpolates the gradient in the OKLab color space." - Björn Ottosson who invented it has an article about it if you want to delve into the maths.
    – Billy Kerr
    Feb 19 at 10:08
  • illustrator is limîtted by the readers of vector graphics. So for print this is the PDF standard. Since the standard is available say at pdfa.org/resource/iso-32000-pdf which includes the limitation of the math that can be used. Photoshop has no such limitation.
    – joojaa
    Feb 20 at 17:18

2 Answers 2

1

This answer has several references so sit down and have a coffee...

I do not know what is the interpolation method, but most likely is simply linear. Making a curved one would be too complex (requiring for example either some matrix or gamma function)

Here is what I understand by linear or curved. How to create a vibrant gradient with 2 Pantone Colors?

We also need to define "perceptual". "Perceptual" in a gradient could need a variation in hue. Here is an explanation: How can I make the color white look as white as possible?

However, the path of a gradient between two colors depends on the color model and the colors themselves, mainly if they do not share the same hue. I can think of at least 5-6 paths to do a gradient between two colors, and those are all linear paths (without counting any "acceleration" or intermediate steps)

Generating a series of colors between two colors

Let me extract the image from that post:

enter image description here


So, to answer your question you need to define what path you want.

A method can be the same as I used on the first link. How to create a vibrant gradient with 2 Pantone Colors?

  • Use transparency
  • Use Multiply blending mode

This will result in a linear path (1) Or if you change the starting point of your transparency, you can end with path (3)


If you want to make controlled steps in a gradient you need to do the math for each channel.

Let's say your color goes from R0 G200 B0 to R200 G0 B0

As you can see they are complementary. Each channel will go from 0 to 200 having R100 G100 B0 at the middle.

But you can tweak the middle value to something line R200 G200 B0.

So you need to choose the path.

1

Disclaimer: The writing below is based on my guesses with no actual knowledge of the math behind Photoshop CC's gradient mixing formulas.

There's actually a comment which suggests a receipe: Insert in Illustrator to your gradient intermediate stops. Pick the needed intermediate colors from an existing perceptually mixed gradient. That's because Illustrators own gradient mixing formulas are fixed, they cannot be changed.

Illustrator (and also legacy Photoshop and many other programs) makes for example this 2 stop gradient from pure sRGB red #ff0000 to pure sRGB cyan #00ffff:

enter image description here

The midpoint is the expected 50% grey #7f7f7f, but it looks too dark for many of us. That problem has occurred few times in earlier questions. People have somehow mixed (blur, transparency, gradient, smudge, mixing brush) red and cyan and wondered why it's so dirty. The grey in the middle should be brighter, like this:

enter image description here

I'm sure that some of us also see there's some orange in the middle of the 1st gradient. It's an illusion caused by mixing red and somehow greenish cyan lights. But that orange also should be brighter to meet the expectations, maybe like this:

enter image description here

There's a separate rectangle filled with the orange that looks right for me. The gradient has three stops: Left=red, Midpoint=the shown orange and Right=cyan. I made my own perceptually right gradient just by inserting an intermediate stop.

But do these have anything common with Photoshop's new gradient mixing options? There's 2 reason why I cannot say:

  1. Adobe keeps all math behind its software functions secret. Reverse engineering is needed to find the formulas, but it's too big technical challenge for most of us and it cannot be done legally, because using Adobe software means one has accepted the end user license which prohibits reverse engineering and distributing the internals of the software. So, do not expect you'll find the formulas easily.

  2. My Adobe CC subscription has been expired and I do not pay a new one as long as I do not need it. I need it when I must work with a file which doesn't work in legacy versions.

The version in my 2nd image was drawn in linear gamma (=1.0) RGB mode. Such modes can be found in Krita and GIMP. Making color mixes in linear gamma mode is an old trick to avoid apparently too dark mixes. Photoshop has had it for ages. It's the 32 bit deep RGB mode. Switch the 32 bit mode ON before you draw a gradient. Of course, the result is converted to sRGB for displaying and you may need to return to bit depth=8 mode, but the the conversion doesn't spoil the fact that the original mix was made in linear gamma mode. I guess my 2nd image is closely the same as Photohop's gradient mixing option "Linear"

There's no way to force Illustrator to make color mixes in linear gamma mode, so paste a copy of the gradient to Illustrator and pick the midpoint stop color from it.

The orange midpoint stop version will get a receipe for the midpoint stop color. It needs Lab color mode, so it's also beyond the capabilities of Illustrator. You need a program which can convert your endpoint stop colors to Lab mode. Photoshop at least does it in the color selection dialog. There are also color conversion websites which convert at least sRGB to Lab (=CIELAB) and back. Converting a certain print color profile CMYK to Lab and back happens only in a program which understands both CMYK printing and Lab. Photoshop is one.

Here https://raphlinus.github.io/color/2021/01/18/oklab-critique.html is a handy interactive tool which draws two-stop gradients. The gradients are created in different color spaces (sRGB, CIELAB and a few others), but the endpoint stop colors are given and the gradient is shown in sRGB. You can pick to your sRGB gradient intermediate stop colors from a screenshot if you like them. A competent programmer might be able to reverse engineer how the gradients are generated in math, but I cannot give any explanations. The whole linked article is written to compare methods which are said to mix gradients better than the commonly used methods which make 3D curve fitting interpolations in sRGB or CIELAB color spaces. Unfortunately I do not have a slightest idea which curves and interpolations are used and which ones make it look pleasant as color.

In theory you could convert the colors purely with math formulas (they can be found easily), but it's painful. The formulas are available also as spreadsheets in some enthusiast's websites. Unfortunately I cannot tell one which I know so well that I could recommend it.

So, convert your gradient endpoint colors to Lab. Let the results be (L1,a1,b1) and (L2,a2,b2). Calculate the averages L3=(L1+L2)/2 a3=(a1+a2)/2 b3=(b1+b2)/2. The average (L2,a3,b3) is the right Lab color for the gradient midpoint stop. Convert it back to RGB or CMYK to use it in Illustrator.

The average is the result of "linear interpolation between the Lab numbers of the gradient endpoint stops" I checked if a gradient drawn in Lab color mode uses linear interpolation for the whole gradient. Picking colors revealed that it's not this simple. There's obviously tried something finer because the common CIELAB color space (Lab in Photoshop) is not perceptually fully linear and some room still exists for improvements. Different programs interpolated gradients differently in their CIELAB color mode implementations. I tried Affinity Designer, Krita and Photoshop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.