Here's more info to help with understanding what I'm doing. It's the same thing from above with with some added stuff to it. Thanks again for your help!
I need to convert an image from RGB format to LMS format using matrix's and an array of double to hold the LMS values as they're created. I need to take each pixel (R, G, and B) and and multiply it by the combined matrix shown below. Any ideas? I also know that I need to convert the byte value: (val + 256) % 256.
{0.3811,0.5783,0.0402}
{0.1967,0.7244,0.0782}
{0.0241,0.1288,0.8444}
Then, after I convert it to RGB, I need to go back to LMS. I need to create an array of byte to hold the RGB values as they are created. Take each pixel (L, M, and S) and multiply it by combined matrix as shown below. I have to remember to clamp the value between 0 and 255 before assigning into RGB which is a byte array.
{4.4679, -3.5873, 0.1193}
{-1.2186, 2.3809, -0.1624)
{0.0497, -0.2439, 1.2045)
Here's some of my code that I've already written:
- public static void main(String args[]) throws IOException
-
{
-
DataInputStream rd = new DataInputStream(System.in);
-
char c1=(char)rd.readUnsignedByte();
-
char c2=(char)rd.readUnsignedByte();
-
int width=getNumber(rd);
-
int height=getNumber(rd);
-
int colorValue=getNumber(rd);
-
System.out.println("P6" + " " + width + " "+ height + " 255");
-
byte image[] = new byte[width*height*3];
-
double lms[] = new double[width*height*3];
-
rd.read(image);
-
-
double A[][] = {{0.3811,0.5783,0.0402},{0.1967,0.7244,0.0782},{0.0241,0.1288,0.8444}};
-
double D[][]=new double[3][1];
-
double V[][]=new double[3][1];
-
-
for(int i=0; i < image.length; i = i+3)
-
{
-
D[0][0] = image[i];
-
D[1][0] = image[i+1];
-
D[2][0] = image[i+2];
-
V = mult(A, D);
-
lms[i] = V[0][0];
-
lms[i+1] = V[1][0];
-
lms[i+2] = V[2][0];
-
}
-
-
System.out.print(V);
-
}
-
public static double [][] mult(double A[][], double D[][])
-
{
-
double V[][] = new double[A.length][D[0].length];
-
for(int i = 0; i<A.length; i++)
-
{
-
for(int j = 0; j<D[0].length; j++)
-
{
-
for(int k=0; k<A[0].length; k++)
-
{
-
V[i][j] = V[i][j] + A[i][k]*D[k][j];
-
}
-
}
-
}
-
return V;
-
}
-
-
}
-
Thanks for your help!