Ask Your Question

Revision history [back]

I do think both suggestions contain wrong information. To make it a little more clear look at the link that @FLY provided right here. If you go down to the cvtColor function and to the grayscale to rgb conversion you will see the following statement.

Gray to RGB[A]: R <-- Y, G <-- Y, B <-- Y, A <-- \max(ChannelRange)

Here comes in play directly what @Allyson Martins suggested. When you got a grayscale image you only have intensity values from 0 - 255 of each pixel. You have basically no idea how the relation of green, blue and red is in that specific pixel.

So you either have to

  1. Define a relation between the channels and use that to backproject the colors
  2. Or you do like openCV and take the same intensity values for each channel. This will look like a grayscale image but in fact it is not! You changed from the 8UC1 type to 8UC3 type thus having three color values, just all the same weight, resulting in a grayisch colored color image.