google / neuroglancer

WebGL-based viewer for volumetric data
Apache License 2.0
1.02k stars 283 forks source link

Add a transfer function shader widget #582

Closed seankmartin closed 1 month ago

seankmartin commented 2 months ago

Adds a new shader widget directive transferFunction. Transfer functions can be used to map specific data values to color and opacity values via a set of control points. In between control points, the values are linearly interpolated.

A preview of the underlying lookup texture is shown in the UI panel for a transfer function.

Points are added to the panel via a click, their color is changed by setting a new color in the picker, and then right-clicking the point. Points are removed via a modifier and double-click on the point.

chrisj commented 1 month ago

@seankmartin could you share a ng link that demonstrates the feature? I tried to get a basic grayscale image out of it but I think I'm missing something

https://neuroglancer-demo.appspot.com/#!%7B%22dimensions%22:%7B%22x%22:%5B1.6e-8%2C%22m%22%5D%2C%22y%22:%5B1.6e-8%2C%22m%22%5D%2C%22z%22:%5B4e-8%2C%22m%22%5D%7D%2C%22position%22:%5B32102.173828125%2C15304.3671875%2C3552.684326171875%5D%2C%22crossSectionScale%22:0.6126263941844161%2C%22projectionScale%22:65536%2C%22layers%22:%5B%7B%22type%22:%22image%22%2C%22source%22:%22precomputed://https://bossdb-open-data.s3.amazonaws.com/flywire/fafbv14%22%2C%22tab%22:%22rendering%22%2C%22shader%22:%22#uicontrol%20transferFunction%20colormap%28window=%5B0%2C%20100%5D%2C%20channel=%5B%5D%2C%20defaultColor=%5C%22#000000%5C%22%29%5Cn%5Cnvoid%20main%28%29%20%7B%5Cn%20%20emitRGBA%28colormap%28%29%29%3B%5Cn%7D%5Cn%22%2C%22shaderControls%22:%7B%22colormap%22:%7B%22controlPoints%22:%5B%5B68%2C%22#000000%22%2C0.5137254901960784%5D%2C%5B94%2C%22#ffffff%22%2C0.8313725490196079%5D%5D%7D%7D%2C%22name%22:%22fafbv14%22%7D%2C%7B%22type%22:%22image%22%2C%22source%22:%22precomputed://https://bossdb-open-data.s3.amazonaws.com/flywire/fafbv14%22%2C%22tab%22:%22rendering%22%2C%22shaderControls%22:%7B%22normalized%22:%7B%22range%22:%5B0%2C200%5D%7D%7D%2C%22name%22:%22fafbv141%22%2C%22visible%22:false%7D%5D%2C%22selectedLayer%22:%7B%22size%22:906%2C%22visible%22:true%2C%22layer%22:%22fafbv14%22%7D%2C%22layout%22:%22xy%22%7D

seankmartin commented 1 month ago

Hey @chrisj, for sure, no worries!

From the link you sent, I've created a transfer function that mimics an invlerp so you can compare here

More generally, you can add points by clicking, change their color by right clicking after selecting a color in the color picker, and remove points by shift double clicking for something like this

At the moment, the transfer function does not show any indication of the underlying data distribution, which can make creating them a little tricky. Let me know if you have questions, happy to help