Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Did you try something like cvtColor(matProcessed, matFalseColor, CV_GRAY2BGR); and then use matFalseColor to apply the desired color map? It would preserve the original processed data in matProcessed.

Did you try something like [answer edited based on the comments below]

To transform a grayscale image to false color first I would recommend to copy it, i.e. cvtColor(matProcessed, matFalseColor, CV_GRAY2BGR); instead of cvtColor(matProcessed, matProcessed, CV_GRAY2BGR);

To apply a custom colormap you can use either a "manual" method like you described (btw, you have a bug: matProcessed.data[index+0]=B instead of color.blue()), or with the LUT function (http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#lut).

To construct a lookup table (a vector of 256 RGB elements (CV_U8C3 or CV_U16C3)), you have to take some "basic" colors interpolate the values between to get a nice color palette.

Some examples (notation: index1 [R,G,B] -> index2 [R,G,B]->...):

  • shades of blue: 0 [0,0,0] -> 255 [0,0,255].
  • ice: 0 [0,0,0] -> 128 [0,0,255] -> 255 [255,255,255].
  • fire: 0 [0,0,0] -> 85 [255,0,0]-> 170 [255,255,0] ->255 [255,255,255].

To get a color spectrum, build a HSV lookup table: 0 [0,0,0] ->255 [360,0,0], transform it to RGB (cvtColor) and then use matFalseColor to apply the desired color map? It would preserve the original processed data in matProcessed.

it to the image.