Adjusting colors and normalization in Neuroglancer
This page will describe how to adjust colors and normalization in the Neuroglancer viewer.
To adjust the colors or normalization in a Neuroglancer view, you need to go to the right side panel and look for the Shader under the Rendering tab. Look for a small box icon to the right of the word ‘Shader’ and click that. A popup window will appear and the default for grayscale images will appear in the popup. The code should look similar to the code in the Greyscale section below. You can copy and paste the code from the Greyscale, Red, Green or sRGB sections into the Shader window and adjust the values as needed. Decrease the larger number in the range if the images are very low contrast. The upper limit is 65535 for 16bit images.
Greyscale
1 #uicontrol invlerp normalized (range=[0,65535])
2 #uicontrol float gamma slider(min=0.05, max=2.5, default=1.0, step=0.05)
3
4 void main() {
5 float pix = normalized();
6 pix = pow(pix,gamma);
7 emitGrayscale(pix) ;
8 }
The above code will set a grayscale normalized CDF (cumulative distribution function) and a gamma correction slider. Note the value of 65535, this is an upper limit for the normalization of 16bit images. You can adjust this number down to say 5000 for very low contrast images.
Red
Copy the code below into the Shader popup window for red. (Note a very small range (5000) is set for low contrast images). A tool to toggle the color on and off is also included.
1 #uicontrol invlerp normalized (range=[0,5000])
2 #uicontrol float gamma slider(min=0.05, max=2.5, default=1.0, step=0.05)
3 #uicontrol bool colour checkbox(default=true)
4
5 void main() {
6 float pix = normalized();
7 pix = pow(pix,gamma);
8
9 if (colour) {
10 emitRGB(vec3(pix,0,0));
11 } else {
12 emitGrayscale(pix) ;
13 }
14 }
Green
Copy the code below into the Shader popup window for green. (Note a very small range (5000) is set for low contrast images). A tool to toggle the color on and off is also included.
1 #uicontrol invlerp normalized (range=[0,5000])
2 #uicontrol float gamma slider(min=0.05, max=2.5, default=1.0, step=0.05)
3 #uicontrol bool colour checkbox(default=true)
4
5 void main() {
6 float pix = normalized();
7 pix = pow(pix,gamma);
8
9 if (colour) {
10 emitRGB(vec3(0,pix,0));
11 } else {
12 emitGrayscale(pix) ;
13 }
14 }
sRGB
This is for 3 channel sRGB images. Copy the code below into the Shader popup window for sRGB.
1 #uicontrol invlerp toNormalized
2 #uicontrol float gamma slider(min=0.05, max=2.5, default=1.0, step=0.05)
3
4 void main () {
5 emitRGB(vec3(pow(toNormalized(getDataValue(0)),gamma), pow(toNormalized(getDataValue(1)),gamma), pow(toNormalized(getDataValue(2)),gamma)));
6 }
sRGB (option 2)
This is for 3 channel sRGB images. This has 3 normalization sliders. It works well but takes up a lot of room in the rendering panel. Copy the code below into the Shader popup window for sRGB.
1 #uicontrol invlerp red(channel=0)
2 #uicontrol invlerp green(channel=1)
3 #uicontrol invlerp blue(channel=2)
4
5 void main() {
6 emitRGB(vec3(red(), green(), blue()));
7 }