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
.
2 | No.2 Revision |
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]->...):
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 apply matFalseColor
to the desired color map? It would preserve the original processed data in matProcessed
.