Ask Your Question
0

Give random color to each intensity

asked 2019-11-07 02:37:29 -0600

Nbb gravatar image

I have a 2D 100x100 image with intensity in the range [0,36]. How can I assign a random color to each intensity?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2019-11-07 03:36:57 -0600

kbarni gravatar image

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.

edit flag offensive delete link more
1

answered 2019-11-07 03:37:42 -0600

LBerger gravatar image

May be something like that

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-11-07 02:37:29 -0600

Seen: 550 times

Last updated: Nov 07 '19