Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding inverse matrix

I want to find the inverse of the XYZ to LMS colour space matrix. After looking around I found that processing has a transpose function. But I know that the transpose of a matrix doesn't always equal the inverse. I could figure out a way of calculating the inverse manually but does processing have any built in functions for this or has anyone already figure out a way to do this and doesn't mind sharing?

float []lms2xyzConverter(float[] lmsVals){               

   //Normalized to D65
   float[][]xyz2lms =  {   {0.4002 , 0.7076 , -0.0808},           
                           {-0.2263 , 1.1653 , 0.0457},       
                           {0.00000 , 0.00000 , 0.9182} }; 

   float [][]lms2xyz = xyz2lms.transpose();
}; 
like image 661
Will Avatar asked Jan 28 '26 21:01

Will


1 Answers

Transpose is not the same as inverse for colour matrices, as they are not orthogonal (M transpose times M = I)

There are libraries for Processing that can invert matrices: http://adilapapaya.com/papayastatistics/

float[][] invA = Mat.inverse(A);

Alternatively there are a huge number of matrix libraries for Java, which you might be able to use, e.g. https://code.google.com/p/efficient-java-matrix-library/.

However, as you only need 3D matrix inversion, you could invert it manually using 9 lines of code, each with the appropriate formulae (see http://www.wikihow.com/Inverse-a-3X3-Matrix). This would probably be faster and use less memory than any of the pre-made solutions!

like image 159
Sanjay Manohar Avatar answered Jan 31 '26 11:01

Sanjay Manohar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!