in reply to Re^4: Mapping function values to colors
in thread Mapping function values to colors

Can you read this?

Tip! Load the image into your favorite image editor and flood fill the background with white.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re^5: Mapping function values to colors

Replies are listed 'Best First'.
Re^6: Mapping function values to colors
by gone2015 (Deacon) on Dec 11, 2008 at 15:15 UTC

    Indeed.

    You may, nevertheless, wish to fix the fact that when $v >= $vmax both the original and the updated code give (r=  0 g=  0 b=  0) cf the expected (r=255 g=255 b=255).

    As to performance, I ran a little benchmark over 1,000,000 random values -200..+200:

                      s/iter colorRamp1785_u colorRamp1785_2 colorRamp1785_3
      colorRamp1785_u   7.26              --            -19%            -65%
      colorRamp1785_2   5.85             24%              --            -57%
      colorRamp1785_3   2.54            186%            130%              --
    
    YMMV, of course. (colorRamp1785_3 is, of course, a direct look-up, after normalising $vmin..$vmax to 0..1785.)

    [Colour reproduction and colour perception being what they are, I imagine there's a cunning way of mapping a linear scale to something which appears linear. I just wish I knew what that was :-(]

    Update: FWIW the fastest I can make a direct look-up is the code below, which benchmarks:

                    s/iter colorRamp1785_u colorRamp1785_1 colorRamp1785_2 colorRamp1785_d
    colorRamp1785_u   7.23              --             -8%            -20%            -67%
    colorRamp1785_1   6.62              9%              --            -13%            -64%
    colorRamp1785_2   5.79             25%             14%              --            -59%
    colorRamp1785_d   2.37            205%            179%            144%              --