Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Create a LUT (look-up table) which is a 256 by 1 color image. This will store the colors for each intensity. If your image contains only 36 levels, you can set only the first 36 values.

Mat lookUpTable(1, 256, CV_8U3);
Vec3b p = (Vec3bv)lookUpTable.data();
for( int i = 0; i < 36; ++i)
    p[i] = Vec3b(rand()%256,rand()%256,rand()%256);
LUT(image,lookUpTable,result);

This will give totally random colors to the different levels. It might be wiser to use some nice, but still random colors. Define the LUT un the HSV space, and set saturation and value to 255:

for( int i = 0; i < 36; ++i)
    p[i] = Vec3b(rand()%180,255,255);
cvtColor(lookUpTable,lookUpTableBGR,COLOR_HSV2BGR);

You might also want to try a systematic LUT instead of a random one. In this case just change the line to p[i] = Vec3b(i*5,255,255);. In this case the hue of the succeeding levels will differ by 10°, a subtle, but noticeable difference.