MINI-THREAD: Continuing the colormap approximation quest I began yesterday! We'll start with Robin Green's suggestion, after a brief recap from yesterday... 1/ https://twitter.com/fatlimey/status/1249928805369536512
So the goal here is to numerically approximate a couple of cyclic (periodically repeating) colormaps called HSLuv and HSPuv. I wrote a shader to do this yesterday, it's up at https://www.shadertoy.com/view/tdBcRG  2/
From bottom to top in the image above, we have HSLuv palette, my polynomial approximation, HSPuv palette, and then my other approximation. We're happy if they match. But they don't. Here's a comparison: 3/
Hence @fatlimey's suggestion. So let's try it out. Shader at https://www.shadertoy.com/view/WdSyzK , output and comparison plots attached here. It's definitely a better match! 4/
Forgot to note in the tweet above that the rational approximation and the normal polynomial have the same number of coefficients (7 for each color channel), so it is an🍎to🍎comparison.

We'll hold to 7 coefficients for the remaining examples too. 5/
The fellow geek who nerd-sniped me into this quest pointed out that the palettes are periodic, so why not try Fourier series?

Fair point, friend!

It does better than vanilla polynomial but not as good as rational polynomial. Shader at https://shadertoy.com/view/WsSyzK , results below: 6/
So if rational polynomial is better than polynomial, what's better than Fourier series? Is "rational Fourier series" a thing? I don't know but I tried it and it works better than anything I'd tried so far. Shader at https://www.shadertoy.com/view/3dByzK  7/
By the way, there's no way to get a 7-coefficient rational Fourier series the way I'm defining it (see the shader code for details). I can only do 5 coefficients or 9. That last pic was 5 coefficients. Still beats rational polynomial despite having fewer coefficients! 8/
If we allow ourselves 9 coefficients, we are still beating degree-4 rational polynomials (also 9 coeffs), and the output looks *great*: 9/
By the way, I tried to do a little googling for "rational Fourier series" and didn't come up with much besides this reference: https://apps.dtic.mil/dtic/tr/fulltext/u2/a273660.pdf

Does anyone know if they are in widespread use, or if I came up with something kind of new? 10/
If you're curious about how I did the fitting (and automatically converted outputs to GLSL), check out https://github.com/mzucker/fit_colormaps. Happy to answer questions in replies to this thread! 11/11
You can follow @matt_zucker.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: