rordenlab / MRIcroGL

v1.2 GLSL volume rendering. Able to view NIfTI, DICOM, MGH, MHD, NRRD, AFNI format images.
https://www.nitrc.org/plugins/mwiki/index.php/mricrogl:MainPage
Other
204 stars 32 forks source link

Scripting RBG colors #18

Closed tfettrow closed 3 years ago

tfettrow commented 4 years ago

How can specify an ROI color with the input of RGB values, instead of using the "colorname"?

neurolabusc commented 3 years ago

If you download the new version (v1.2.20201102) you will find a couple ways to. do this.

First, you can modify an existing color scheme - the existing grayscale colorscheme is used here. By default, it has three nodes (black, gray, white). Here I set these to Green (RGB 0,100,0), Cyan (RGB0, 100,200) and yellow (RGB 250,250,170). The alpha is 0, 94, 164 (alpha impacts how translucent the surface is in the rendering). The Scripting/Templates/help provides details on the command. I also show the interactive Color Editor, which helps visualize the adjustment of these three nodes:

import gl
gl.loadimage('spm152')
gl.coloreditor(1)
gl.colorname(0,'Grayscale')
gl.colornode(0,0,0,0,100,0,0)
gl.colornode(0,1,100,0,100,200,94)
gl.colornode(0,2,255,250,250,170,164)

The other option is to generate a color lookup table (.clut) file. These are simple text files, so you can generate them with any text editor, or. dynamically with Python. If you place these files into the MRIcroGL/Resources/lut folder, they will be available in the graphical user interface when you restart MRIcroGL.

import gl
import os
fnm = os.path.expanduser("~")+os.path.sep+'myLUT.clut';
f = open(fnm, "w")
f.write("[INT]\n")
f.write("numnodes=3\n")
f.write("[BYT]\n")
f.write("nodeintensity0=0\n")
f.write("nodeintensity1=128\n")
f.write("nodeintensity2=255\n")
f.write("[RGBA255]\n")
f.write("nodergba0=0|0|0|0\n")
f.write("nodergba1=128|128|0|64\n")
f.write("nodergba2=255|0|0|128\n")
f.close()
gl.colorname(0,fnm)