Solution 1 :
A quick way to map a value to a color by using one of the methods in Color
class.
For example, using Color.HSVToColor
and passing your value in as the “hue” will give you a rainbow color palette. The appropriate mapping will depend on what range the values in your matrix can take. If they are in the range -1 to +1, this will work for you:
float hue = (float) (matrix[i][j] + 1) * 180;
float[] hsv = { hue, 1f, 1f };
int color = Color.HSVToColor(hsv);
Problem :
I’m working with an image in android studio. To make it simple let’s say it only has 9 pixels. The values of the pixel are held in a double matrix in, lets say its something I like this:
double[][] matrix = {{-0.5, -0.4, -0.3},
{-0.1, -0.9, -0.4},
{-0.5, -0.6, -0.9}}
I want to turn each of those doubles into a color int so I can put them into an image pixel by pixel. (In Matlab you’d use something like colormap('jet')
).
Bitmap bitmap = Bitmap.createBitmap(length, height, Bitmap.Config.RGB_565);
for(int i = 0; i< length ; i++ ){
for (int j = 0; j < height; j++){
//Convert number in matrix to color from blue to red
int color;
//Make correlating pixel that color
bitmap.setPixel(i,j, color);
}
}
I have tried using the Scichart SDK but the license is too expensive.
I also tried the Mines package but it depends on Java AWT which is not available in android studio
I can’t find anything on the documentation.
Comments
Comment posted by Lennart Steinke
You need to convert the color values from the input format to the output format. The output format is RGB, with 1 byte for R, G and B. In what format are your input values?
Comment posted by Alext.45
My input values are just doubles.
Comment posted by Lennart Steinke
yes, but what do the values represent? YUV? RGB? HSV? In what ranges?In order to make a meaningful conversion, you need to know what these values represent.
Comment posted by Alext.45
This is a good start. What do I do if my values are in a much closer range? When I tried running that I got the same color for every pixel.
Comment posted by Joni
Then you need to find a way to map the range where they are to the range expected by the color function. For the hue component of HSVToColor, the range is 0 to 360.