Skip to content

How To Make a Color Table

RII-Mango edited this page Apr 9, 2017 · 7 revisions

Custom Color Table (Knot Array)

Papaya supplies a range of color tables, but you can add your own custom color tables as well. To do so, create an array called luts and add color table objects, each with a name and data field.

The data field contains an array of "knots", each containing four values: distance along color table (0 to 1), red value (0 to 1), green value (0 to 1), blue value (0 to 1). The following example produces a "Red-to-Yellow-to-White" color table. You can also add a gradation field to specify if the color between knots should be interpolated (default) or if it should be a constant color (best for segmented regions).

params["luts"] = [{"name": "Custom", "data":[[0, 1, 0, 0], [.5, 1, 1, 0], [1, 1, 1, 1]]}];
params["myImage.nii.gz"]  = {lut:"Custom"};

Custom Color Table (Function)

You can also create a custom object with methods lookupRed(screenVal, imageVal), lookupGreen(screenVal, imageVal) and lookupBlue(screenVal, imageVal), where screenVal is a value 0 to 255 and imageVal is the voxel intensity. That is, for each pixel, its value will be used to lookup red, green and blue values. For example, this color table will create red pixels wherever the screen value is greater than 128, or black otherwise:

var myCustomColorTable = function() { };

myCustomColorTable.prototype.lookupRed = function (screenVal, imageVal) {
    if (screenVal > 128) return 255; else return 0;
};

myCustomColorTable.prototype.lookupGreen = function (screenVal, imageVal) {
    return 0;
};

myCustomColorTable.prototype.lookupBlue = function (screenVal, imageVal) {
    return 0;
};
params["myImage.nii.gz"]  = {lut: new myCustomColorTable()};