0

I have 3 eqns and 2 unknowns Hb and Hbo2, they look like this:

Bxy = AB * HB + AB * Hbo2

Rxy = AR * HB + AR * Hbo2

Gxy = AG * HB + AG * Hbo2

Now I have been trying to use a matrix method in order to solve the unknowns for them equations, which is a pain in the ass cause when I convert it to matrix form I get an irregular matrix because it is 2 unknowns and 3 equations.

Does anyone on here know how to solve n number of equations with n-1 unknowns.

EDIT

Thanks for the responses so far, they have been great.

To help make this more clear, what I am trying to do is work out the concentration of oxygenated and deoxygenated blood at a given pixel in an image. so the variables above correspond to the following.

Rxy Gxy and Bxy, red green or blue absorbed at position x,y. (value between 0 - 255)

AR, AG, AB is the absorption coefficient of light for Red geen and blue wavelengths for blood. (HOWEVER there is a possibility I might have to define different absorption coefficients for oxygenated and deoxygenated blood (as they absorb different amounts of light)).

Hb and Hbo2 is the concentration of Oxygenated and Deoxygenated blood. (these are unknown as I'm trying to map the RGB values to this)

However I have also noticed that the coefficients for Oxygenated and Deoxygenated blood are different so this means the equation could possibly be the following.

Bxy = (ABhb * HB) + (ABhbo2 * Hbo2)

Rxy = (ARhb * HB) + (ARhbo2 * Hbo2)

Gxy = (AGhb * HB) + (AGhbo2 * Hbo2)

The only difference in the above is that the coefficients are different for oxygenated and deoxygenated blood.

This is all part of my Final Year Project at uni for Computer Science, trying to do some functional imaging.

@Chris does the same apply if there is different coefficients, sorry for lack of understanding, Maths is not my strongest point. Just trying to program this algorithm.

Antony
  • 65
  • 2
  • 8
  • 1
    Isn't this better suited for http://math.stackexchange.com/? – Kurtis Nusbaum Oct 19 '11 at 21:05
  • If the coefficients are the same down the columns then @a72's response is what you'd want to do. You effectively have only 1 unknown in this case and no way to determine the contribution of `HB` and `Hbo2` individually. If you have different coefficients in each element of your matrix, then least squares as I prescribed is the right thing to do. – Chris A. Oct 19 '11 at 21:50
  • Sorry, I'm a Computer Sceintist and this is part of my project, I was unsure where to post it and considering it is related to a computing project I figured I post it here, sorry for the mistake. – Antony Oct 19 '11 at 21:51
  • @ChrisA. so it looks like I will have to look up the least squares algorithm, this is because knowing the different concentrations is important for what I am trying to find in the images. Thanks for your help, I will begin my quest into finding out how the Least Squares thing works. – Antony Oct 19 '11 at 21:54
  • I put a link in my post about it. – Chris A. Oct 19 '11 at 22:10
  • @ChrisA. I noticed you have a background in functional imaging and computer vision, thats really sweet, thanks for your help, I will keep you posted on how it goes and weather I can actually map RGB to Oxygenated and Deoxygenated blood correctly. – Antony Oct 19 '11 at 22:17

3 Answers3

2

What you probably want is what's called the least squares solution (see the section on the general problem). To summarize, you are not guaranteed an exact solution depending on your A and b when you are trying to solve A*x=b here.

However, by computing xLS = inv(A'*A)*A'*b you'll get something that's as close as possible to a solution (in the least squares sense). Note that A' means the transpose of A. Also note, if A'*A is not invertible then your system of equations is rank deficient (that means you effectively have less equations than you think.)

If you have:

 Bxy = (ABhb * HB) + (ABhbo2 * Hbo2)
 Rxy = (ARhb * HB) + (ARhbo2 * Hbo2)
 Gxy = (AGhb * HB) + (AGhbo2 * Hbo2)

Then:

 A = [ ABhb  ABhbo2 
       ARhb  ARhbo2 
       AGhb  AGhbo2 ];

 x = [HB
      Hbo2];


 b = [Bxy
      Rxy
      Gxy];
Chris A.
  • 6,817
  • 2
  • 25
  • 43
  • Quick question, what does b and x represent in the above and will it return a vector with 2 values, one for Hb and one for Hbo2? Edit Ooo might have got it, x is the vector Hb, Hbo2 and b is the Vector R,G,B? – Antony Oct 19 '11 at 22:08
  • Thank you so much for the lovely edit Chris you have helped so much. – Antony Oct 19 '11 at 22:18
1

If you have n equations and n-1 unknowns, that means you can eliminate one of the equations, it is irrelevant and dependent on the other two. Figure out which one is easiest to eliminate, substitute, and then you're left with an (n-1)x(n-1) matrix

assuming there is a solution for all three equations that is, it can be found by only solving two of them to get the two unknowns.

In this case, it seems all of your equations are more or less equal, aside from the coefficients, so I don't think it will matter which of the three you chose to exclude. You could simply drop the Gxy equation and end up with the 2x2 pair of:

Bxy = AB * HB + AB * Hbo2

Rxy = AR * HB + AR * Hbo2

resulting in the matrix

[AB AB]

[AR AR]

Dan F
  • 17,654
  • 5
  • 72
  • 110
  • Thanks dan, so it is safe then to remove one of the eqns, in otherwords if i solve for the first two then it folows the third one will also be satisfied. – Antony Oct 19 '11 at 19:34
  • @Dan F eliminating an equation does not bring you down to an `(n-1)x(n-1)` it brings you down to an `(n-1)x(n-2)` since it eliminates an equation and an unknown. This is a class problem called least-squares. – Chris A. Oct 19 '11 at 19:41
  • @Antony - of course not! The third needs not to be satified! But it is just generally impossible to satisfy 3 eqns with fiddling only with 2 unknown variablies!!! And because this is generally impossible YOU must define what you really want - you must specify your question further. – Tomas Oct 19 '11 at 20:16
  • @Chris A It does not eliminate an unknown, in his example, both unknowns are used in all three equations, so eliminating one of the equations does not eliminate an unknown – Dan F Oct 19 '11 at 20:25
  • @Dan F I encourage you to edit your response with an example, because I don't think you're correct on that point. If you go through it for a 3x2 system you'll see what I'm talking about. – Chris A. Oct 19 '11 at 20:40
  • @Chris A, I added an example, i still fail to see how this somehow results in removing one of the unknowns from the system – Dan F Oct 19 '11 at 21:01
  • I have included an edit, hopefully it helps clear things up on what I am actually trying to achieve. Thanks so much for your help guys. – Antony Oct 19 '11 at 21:44
1

The epxression HB+Hbo2 is the same in all 3 equations, and it can be replaced by z=HB+Hbo2 making the three equations

B = AB*z
R = AR*z
G = AG*z

To solve for z do a least squares fit to find

z = HB + Hbo2 = (AB*B+AG*G+AR*R)/(AB*AB+AG*AG+AR*AR)

and the error for each component as

dB = B - AB*z
dR = R - AR*z
dG = G - AG*z

That is all you can do. Somehow you have to decide how to split z into HB and Hbo2. No information about this is given in the problem statement.

John Alexiou
  • 28,472
  • 11
  • 77
  • 133