Continous color table for heatmap

We have an image in which the voxel values are the statistical effect sizes ranging from about -0.3 to 0.9. Most of the image is 0s (voxels that didn’t reach significance). I would like to render this image in a way that negative values are a blue to green ramp (-1, 0), positive values green to red (0, 1), and values of 0 are not shown at all.

I am trying creating color tables but have no luck. I appreciate if someone can guide me.

attached is a sample nRRD file: Box

To give a visual example, this is with my modified color table which supposedly have symmetric values from -2 to 2 with 256 colors.

For whatever reason, the scale bar is displaying values only from -0.1 to 0.3 even though the max and min values for this volume is clearly reported to be -0.3 to 0.9 range

I made progress up to a point. Min/Max window level adjustment is really not intuitiuve to work with. So the remaining issue, how can I supress 0 values to be shown in slide views. Since I cannot enter a split range into the threshold value, threshold setting is not very useful.

In volume rendering I can hack something with manually adjusting things. But I need to be able to do this more consistently with more control over colors, and particularly in 2D as well.
Please provide pointers/suggestions.

Any suggestions to hide 0 values (green background)? @pieper

I tried setting 0 to NaN, but then in slice views it switch to color of minimum value in the dataset (even though the data probe shows it as NaN)

We are still looking for a solution. @jcfr @lassoan

To specify a color transfer function I would recommend using a procedural color node (where you can define any color for any absolute value) instead of a color table (where you specify color values at regular intervals that you later map to some intensity range). See full example in the script repository.

Any suggestions to hide 0 values (green background)?

Display threshold can be used for hiding background.

my values range from negative to positive, zero being in the middle not at the lowest value. How can I just threshold 0, or a range like (-0.0001, 0.00001) ?
There are values close 0 on either side, and they are not discernible if 0 is rendered in the overlay
For example this is the full range

negative only (-0.3 to -0.01)

positively only (0.01 to 0.9)

I want the last two together in the same image.

Here are two solutions, by modifying an existing discrete color table to be a transparent in the center or a continous mapping function to be black in the center.

Option A: Discrete color table

  • Create a discrete color map that has transparent color in the middle and a different color on each side
    • Go to Colors module
    • Select ColorsDivergingBlueRed (a color function that that uses just 3 colors: blue = low
      values, white = center, red = high values)
    • Click Copy button (to create a modifiable copy), accept the proposed default name DivergingBlueRedCopy
    • In the color table, for color 127, set opacity0 (to make the center of the color map transparent, to avoid adding a white haze for values around 0 in the overlay)
  • Select this color map for the overlay volume
    • Go to Volumes module
    • Select Active volumeExp-02...
    • Select Lookup TableDivergingBlueRedCopy
    • Set Window/Level L0 (to make the center at 0)
  • Set this colored image as overlay in the slice view controller
    • Select Exp-02... volume as foreground, set its opacity to around 0.5
    • Select final volume as background

If the abrupt change from transparent to opaque is not desirable then set more colors around the center semitransparent by decreasing their opacity values. It may be easier to do this by editing the color table in a text editor or by Python scripting.

Option B: Continuous color mapping

Opacity cannot be specified for continuous color mapping, so we will use black as center color and use additive image blending.

  • Create a continous color map that has black in the middle and a different color on each side
    • Go to Colors module
    • Select ColorsRedGreenBlue (a color function that that uses just 3 colors: red = low
      values, green = center, blue = high values)
    • Click Copy button (to create a modifiable copy), accept the proposed default name RedGreenBlueCopy
    • Select the middle point (by entering Point1 above the color function editor)
    • Set center color to black (click on the colored square next to it, set the value to black using the brightness control bar on the right side, and click OK)
  • Select this color map for the overlay volume
    • Go to Volumes module
    • Select Active volumeExp-02...
    • Select Lookup TableRedGreenBlueCopy
    • Set Window/Level L0 (to make the center at 0)
  • Select additive image overlay display in the slice view controller
    • Select Exp-02... volume as foreground, set its opacity to 1
    • Select final volume as background
    • Click Blend mode icon and choose Add


Creating the color table is somewhat tedious, so it could make sense to add a transparent/black centered color table to the presets.

3 Likes