0
votes

I have a float array of approximate dimensions 3000x1. This array contains values ranging from between -10^(-3) to 10^(-3). I want to use these values to colour an image on the display of an Android phone using the setColor method, which accepts an RGB value as an int.

I want the minimum values, e.g. -10^-3 to appear blue, and as you approach 0 to become more green. From 0 onto the maximum values the colour should go from green to a yellow/orange/red colour. I am fairly confident that this is an easy problem to solve.

Essentially, min(my_array) should get assigned with an approximate 0x0000F0. As we go from min(my_array) towards 0, the colour should gradually become more turquoise, until it reaches green. From there on it should head towards yellow and red, until reaching max(my_array).

Would I need to divide the RGB map into say 3000 segments. Then I could order my array into ascending order, and add as a 2nd column the corresponding RGB values, in the ascending order. I am then unsure about how to get the array back into the original order however.

1
Actually, no, my proposed method in the last paragraph wouldn't work, because if there is a substantial difference in my minimum values, they would appear to have more or less the same colour. The mapping would need to simply accept values from within the -10^-3 to 10^-3 range and simply expand that range and map it to 0x0000FF up to 0xFF0000 for example. - Panos Panteleon

1 Answers

0
votes

I think you should quantize your range -10^(-3) to 10^(-3) to at-least 512 values and use first 256 values for blue, 129 to 364 values for green and 257 to 512 for red. For example:

quantized_array[0] = -10^(-3)   ->   rgb = 0x0000ff
quantized_array[128] = some val ->   rgb = 0x004488
quantized_array[256] = 0        ->   rgb = 0x00ff00
quantized_array[364] = some val ->   rgb = 0x884400
quantized_array[512] = 10^(-3)  ->   rgb = 0xff0000