Give random color to each intensity
I have a 2D 100x100 image with intensity in the range [0,36]. How can I assign a random color to each intensity?
I have a 2D 100x100 image with intensity in the range [0,36]. How can I assign a random color to each intensity?
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.
May be something like that
Asked: 2019-11-07 02:37:29 -0600
Seen: 746 times
Last updated: Nov 07 '19