2

I am using this code and data when I use this command:

[imgw, imgwr, map] = tpswarp(img, outDim, Zp, Zs, interp);   , 

I get this error:

Matrix is close to singular or badly scaled. Results may be inaccurate.

Is there any reason for this error? How I can resolve this issue and run the code? Should I change the Zp and Zs?

rayryeng
  • 102,964
  • 22
  • 184
  • 193
Sam
  • 939
  • 5
  • 14
  • 41
  • I think it is warning you about bad cancellations in some calculations due to floating-point numbers being inaccurate in comparision to "real" numbers. I don't know which calculation it is in particular, but I would guess that it is either the `inv()` operations or the `tpsMap()`. You do know what it means, when a matrix is singlar or badly scaled, right? – Soana Sep 02 '14 at 06:43
  • Thanks for your comments. Yes, I think the problem is about Zp and Zs, but these matrices are constant and don't know that how I should change them! – Sam Sep 02 '14 at 06:50

1 Answers1

2

When a matrix is singular or badly scaled, this means that your matrix is ill-conditioned. This means two things:

  1. The matrix's inverse has a very inaccurate inverse, so solutions using this matrix will be very inaccurate.
  2. When you subject the matrix to small changes, any numerical calculations that you use with the matrix will have such large differences in the output and so the results are unreliable.

The error you're getting is probably attributed to Zp and Zs. Also, this most likely means that Zp and Zs are poorly constructed. Double-check its construction and try again.

As a side question, what is Zp and Zs? Once I know this, I'll edit my post and suggest ways to circumvent this error.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • Thanks for your comments. Yes, I think the problem is about Zp and Zs, but these matrices are constant and don't know that how I should change them! That is why I linked to the code and data. – Sam Sep 02 '14 at 06:52
  • First of all, this code uses Zp as the original coordinate in "img" and tries to warp this image in the destination location which are Zs. Therefore, Zp and Zs are coordinates. – Sam Sep 02 '14 at 06:56
  • I explained the Zp, Zc :) – Sam Sep 02 '14 at 07:39
  • @Sam - OK. Perhaps the source and destination co-ordinates you chose are in such a way that there is no solution to warp from one co-ordinate system to another. What happens when you make `Zp` and `Zs` the same? You should theoretically get the same output. Try that first and see if you get any errors. Once you do that, try moving all of the points over by a known shift (like x = -2 and y = 2 or something). Keep varying the points slightly until you get that error again. Also, check out this post. This may help with regards to singular matrices: http://stackoverflow.com/q/7975244/3250829 – rayryeng Sep 02 '14 at 14:13
  • Actually there are a bunch of points in the image that I don't want to change their values, that is why I have added some points as constraint. – Sam Sep 02 '14 at 16:58