# Scalar Color Mapping has too many control points

**URL:** <https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741>\
**Category:** Support\
**Tags:** volume-rendering\
**Created:** [September 15, 2023, 4:32pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741 "2023-09-15T16:32:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 15, 2023, 4:32pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/1 "2023-09-15T16:32:19Z")

</div>

In the latest stable on Linux, when I enable volume rendering in one of my 16 bit scans (without using a preset), too many control points on the scalar color map is created.

This makes it too tedious to reorganize colors. Is used to be 4-5 points as I recall. Is there a reason why it has increased so much.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/6/867712af53a97ce1bf26045c11a6f28e235b80eb.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 15, 2023, 6:00pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/2 "2023-09-15T18:00:09Z")

</div>

The change was necessary to ensure that the volume’s color map is copied to volume rendering color transfer function with acceptable accuracy. We had to find a balance between sufficient color reproduction and the ability to manually edit the color mapping, that’s why the number of control points are limited to 24. See detailed description here:

> <https://github.com/Slicer/Slicer/commit/35e5586bdb6749376864522b20a2dfda5dab33fc>
>
> When a color node with few color table entries (such as fMRI) was used for showi…ng a volume, the "Synchronize with Volumes module" button in volume rendering module very inaccurately copied the color entries to the color transfer function. The problem was that only every 64th color table entry was copied. Fixed the issue by copying up to 24 color entries (evenly sampled in the lookup table) of the table into the transfer function. This number is large enough to accurately represent a color table, but not too high so that users can still edit the color transfer manually.
> 
> Also fixed synchronization of continuous color mapping. All control points of continuous color maps are copied, so these are copied in full fidelity.
> 
> Fixes the problem reported at https://discourse.slicer.org/t/the-colormap-in-volume-rendering-is-wrong-when-using-fmri-lookup-table-in-volume/30186

What could be improved is to change the trivial 256-entry color tables (vtkMRMLColorTableNode) to procedural color nodes (vtkMRMLProceduralColorNode), which define a color transfer function by a few control points. For example, the 256 table items of the gray color node could be replaced by a color transfer function that contains 2 control points. Control points of procedural color nodes are copied to volume rendering transfer functions and they remain easily editable there, because these color maps are typically defined by just a few control points.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 15, 2023, 6:12pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/3 "2023-09-15T18:12:41Z")

</div>

The issue is there is no easy way of removing multiple control points quickly. It requires a lot of mouse clicks to remove them one by one.

For these smooth colors (e.g. gray), only the 3-4 control points would suffice (in fact right at the same control point spots at where the ramp for opacity map is.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 15, 2023, 6:25pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/4 "2023-09-15T18:25:45Z")

</div>

It is really easy to delete control points: click on one and keep hitting Delete key until all unnedded control points are gone. It takes about 10 seconds to delete all the 24 control points.

Indeed, most of the color maps are “smooth” and can be described by 2 to 5 control points. As I described above, they could be replaced by color transfer functions, but someone would need to reverse-engineer them: determine what control points and color space choice reproduce the original table values.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 15, 2023, 6:44pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/5 "2023-09-15T18:44:30Z")

</div>

> [@lassoan](#):
>
> It is really easy to delete control points: click on one and keep hitting Delete key until all unnedded control points are gone. It takes about 10 seconds to delete all the 24 control points.

Thats a lot of clicks, and the main problem it is not a one-time thing, you have to do it again and again for every new transfer function you are creating.

As a comprise could be possible to do a right-mouse click option that says “remove all control points”. Because it would be way faster to add 3-4 points on where you want them to be than to remove 20 one by one.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 15, 2023, 7:11pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/6 "2023-09-15T19:11:21Z")

</div>

Making removing all control points easier might be an acceptable workaround for some use cases and for some color maps. However, it would be better to address the root cause of the issue: use the minimum necessary number of control points to define a color map. That would allow convenient editing without losing any information.

Are you only interested in the gray colormap?

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 15, 2023, 7:20pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/7 "2023-09-15T19:20:31Z")

</div>

Most often for microCT we start with gray and then adjust colors.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 15, 2023, 9:44pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/8 "2023-09-15T21:44:09Z")

</div>

Aren’t the uCT… presets good enough as a starting point? If you can detect a micro-CT automatically then you can write a Subject Hierarchy plugin that sets up volume rendering using a uCT preset by default.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 15, 2023, 10:42pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/9 "2023-09-15T22:42:13Z")

</div>

Those can be good enough starting points for mineralized tissue scans, but ultimately there is wide range of intensities based on voltage, filter and (if used) contrast solution.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 16, 2023, 7:15pm UTC](https://discourse.slicer.org/t/scalar-color-mapping-has-too-many-control-points/31741/10 "2023-09-16T19:15:32Z")

</div>

It seems that the goal is not to copy the window-level preset but to make it easier to create good volume rendering transfer functions. To achieve this, we could add more volume rendering presets, and maybe we could also develop a new feature: applying window/level used in n the slice view to shift/scale the volume rendering transfer functions.
