Complex Number Issue

4 visualizzazioni (ultimi 30 giorni)
Mark
Mark il 11 Feb 2011
I'm working on an image processing problem that keeps giving me a complex number. Is it possible to get this number in some useable form? If I solve the problem in mathematica i get s approches 0. Please see code below. I'm getting an imaginary number on spos and sneg.
Xell = (P1(1)-(XSize/2))*pixelSx; %-0.2182 Xelr = (P2(1)-(XSize/2))*pixelSx; %-.0269 Xerl = (P4(1)-(XSize/2))*pixelSx; %.8085 Xerr = (P5(1)-(XSize/2))*pixelSx; %1.0348
% Yaw (The Rotation Angle of Y-Axis, Beta)
I2 = (((Xerl - Xerr)*(Xell - Xelr))/((Xell - Xerl)*(Xelr - Xerr))) Q = 1/sqrt(I2)-1; M = -1/(2+Q);
u_num = ((Xell - Xelr)*(Xerl - Xerr)*M*(Xelr - Xerl)-(M)^2*(Xell - Xerr)*(Xelr - Xerl)^2); u_div = ((Xell - Xelr)*(M*(Xelr - Xerl) - (Xerl - Xerr))); u = u_num/u_div;
spos = (Xelr - Xell + Xerl - Xerr - Q*Xell + Q*Xelr + Q*Xerl - Q*Xerr + (4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2))/(Q*Xell - Q*Xelr + Q*Xerl - Q*Xerr); sneg = -(Xelr - Xell + Xerl - Xerr - Q*Xell + Q*Xelr + Q*Xerl - Q*Xerr + (4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2))/(Q*Xell - Q*Xelr + Q*Xerl - Q*Xerr);
Beta0neg = atand(f/((sneg-1)*u)); Beta0pos = atand(f/((spos-1)*u));
  1 Commento
David Young
David Young il 11 Feb 2011
It's a good idea to mark code as such, either by indenting it, or by selecting it and using the "{} code" button. Otherwise it gets wrapped, the questions is hard to read, and you have to reinsert line breaks if you copy the code.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 12 Feb 2011
You do appear to have transcribed the equations from the paper, except that they call I2 "I1".
I tested under the hypothesis that the values you gave might be off by a constant multiple (e.g., wrong sign), but my tests show that there is no possible common multiple of those specific values that would not lead to a complex solution. Except that is, if they are all 0, in which case the solution is undefined.
Keeping the values you have for the first three variables and varying Xerr:
The first branch of s has a solution from Xerr = -infinity to Xerr = -0.0269 except for a singularity at -0.2182, and the first branch of s has a solution from Xerr = 5.290073505 to infinity.
The second branch of s has the same domains except that at first glance it does not have the singularity (but I might not have looked closely enough).
If I use the first two variable values, and set Xerr = Xerl + t and set t as the difference between the Xerr and Xerl values you gave, then I can solve for the locations in which s would be well-defined -- the places Xerl would have to be in order to support that roughly 0.2 difference.
The two branches of the resulting equations have solutions over the range Xerr = -.44523207408446748385 to -0.026167925986932516223 excluding -.2532 to -.2182, with a singularity near -.44450000016449370396 and another at -0.026899999936273041138 . The singularities are very close to the endpoints; one of the branches is complex between the left end-point and the left singularity.
Compare the -0.2182 to -0.0269 range of Xell and Xelr, and if we rule out the possibility of the right eye being more negative than the left eye, then we are left only with the narrow range from -0.0269 to -0.026167925986932516223 excluding the singularity at -0.026899999936273041138 . One of the branches goes to -infinity, the other branch to +infinity, converging to 23.820876156282195822 at the right-hand end-point.
Thus, we cannot say that the equations are unsolvable given those left eye coordinates and the right eye width, but the domain of solutions under those conditions is tiny and completely unrealistic, requiring the eyes to be about 0.0008 apart.
So... we are left with either the equations being wrong or the coordinates being wrong.
The coordinates are probably wrong. Look at figure 4 in the paper, showing the projections that form the four variables. Now look at the top left of that figure, and notice the compass: it shows x increasing up the page. Now look at the order of the variables: it shows Xell as the most positive, Xelr just below that, Xerl below that, and Xerr least positive. That is exactly the opposite order of increasing value compared to the coordinates you gave. Even if you use a negative Beta angle, the order would be the same unless you go right past +/- Pi/2 and exchange left and right (i.e., the picture being upside down.)
Knowing the coordinates to be in the wrong order, I tried again with some permutations of the coordinates and their signs. Unfortunately, none of the permutations I tried resulted in a real-valued s.
I would have to study further to see what the relative values would have to be to increase the eye distance. But it is late on a Friday evening, and I am becoming more convinced that the equations are probably wrong.

Più risposte (3)

Mark
Mark il 11 Feb 2011
Xell = -0.2182;
Xelr = -0.0269;
Xerl = 0.8085;
Xerr = 1.0348;
I2 = (((Xerl - Xerr)*(Xell - Xelr))/((Xell - Xerl)*(Xelr - Xerr)));
Q = 1/sqrt(I2)-1;
M = -1/(2+Q);
u_num = ((Xell - Xelr)*(Xerl - Xerr)*M*(Xelr - Xerl)-(M)^2*(Xell - Xerr)*(Xelr - Xerl)^2);
u_div = ((Xell - Xelr)*(M*(Xelr - Xerl) - (Xerl - Xerr)));
u = u_num/u_div;
spos = (Xelr - Xell + Xerl - Xerr - Q*Xell + Q*Xelr + Q*Xerl - Q*Xerr + (4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2))/(Q*Xell - Q*Xelr + Q*Xerl - Q*Xerr);
sneg = -(Xelr - Xell + Xerl - Xerr - Q*Xell + Q*Xelr + Q*Xerl - Q*Xerr + (4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2))/(Q*Xell - Q*Xelr + Q*Xerl - Q*Xerr);
Beta0neg = atand(f/((sneg-1)*u));
Beta0pos = atand(f/((spos-1)*u));
  1 Commento
David Young
David Young il 11 Feb 2011
Thanks! But even better to edit the question!

Accedi per commentare.


Walter Roberson
Walter Roberson il 11 Feb 2011
The subexpression
(4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2)
corresponds to the sqrt(b^2-4*a*c) term of a quadratic. Strip off the ^(1/2) layer and evaluate the subexpression. With the values you have provided, it comes out as -4.1857998 so naturally you will get a complex number in evaluation of both spos and sneg.
If you go back to your original question and substitute in those numeric values together with the expression you give here for "Q" as the value of "q" in that question, you end up with asking to solve
.8453380468 = -(s-1)*(s-1.497771143)/((s+1)*(s+1.497771143))
If you set aside the leading negative for a moment, you can see this is the ratio of two parabolas that are both open upwards and that are mirror images around x=0. The two will have different signs only in the neighbourhood +/- (1, 1.497771143) and so for most values of s, the ratio will be positive. But that positive number is negated by the leading negative, so for most real values of s, the expression as a whole will be negative. You are trying to solve a positive value equaling an expression that is usually negative in reals. It should therefore be considered to be quite plausible that there is no real valued solution.
If you go back to your original question but leave q undefined for a moment, and drop in the other values you give here, then solve for s, and examine the conditions under which that s will be real-valued, you find you need -2.113345117*10^11*q^2-4.226690234*10^11*q+1.495019985*10^9 to be non-negative. That occurs in the range q = (-2.003530860, 0.003530860320) . If you then evaluate the formula for Q that you give in this posting, using the numeric values you supplied, then you will find Q = 4.017910695 which is well outside the range of solution.
Therefor, unless your expression for Q is quite wrong, you are not going to be able to come up with a real-valued solution for this problem.

Mark
Mark il 11 Feb 2011
I'm using these equations from a white paper determining the pose of a head in monocular image. To determine yaw, it states that s can be got from the following equation:
(Xell-Xelr)/(Xerl-Xerr) = -(((s-1)*(s-(1+(2/Q))))/((s+1)*(s+(1+(2/Q)))))
Q equals the next equation and Xell, Xelr, Xerl and Xerr were displayed in the question above. Q is:
Q = (1/sqrt(I2))-1;
and I2 is this:
I2 = (((Xerl - Xerr)*(Xell - Xelr))/((Xell - Xerl)*(Xelr - Xerr)));
When I solve for s, I get the two equations:
spos = (Xelr - Xell + Xerl - Xerr - Q*Xell + Q*Xelr + Q*Xerl - Q*Xerr + (4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2))/(Q*Xell - Q*Xelr + Q*Xerl - Q*Xerr);
sneg = -(Xelr - Xell + Xerl - Xerr - Q*Xell + Q*Xelr + Q*Xerl - Q*Xerr + (4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2))/(Q*Xell - Q*Xelr + Q*Xerl - Q*Xerr);
The white paper has experimental results in it, I just can't figure out where I'm going wrong.
Thanks, Mark
  3 Commenti
Mark
Mark il 11 Feb 2011
I'll send the paper to your email. Thanks for the help! I've been banging my head on this issue for a few days.
Mark
Mark il 11 Feb 2011
I'm stumped with this one. The paper appears to be pretty easy, but the numbers do not work out.
Thanks for your help!

Accedi per commentare.

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by