Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug in cp2tform?

302 views
Skip to first unread message

Jakkris Tangkuampien

unread,
Dec 7, 2001, 1:46:16 AM12/7/01
to
Hi,

I've corresponded on this matter with someone from Mathworks before.
Initially, I thought it might have been the fact that I was giving
the function too many input points (something like 10000!). Now
cp2tform gives me the message

"
??? Error using ==> cp2tform (findPolynomialTransform)
At least 15 non-collinear points needed to infer polynomial transform.

Error in ==> C:\MATLAB6\toolbox\images\images\cp2tform.m
On line 142 ==> [trans, output] = feval(findT_fcn,uv,xy,options);
"

The control points I used this time around were selected using the
Control Point Selection. I selected 16 points which the Selection
Tool determined to be good enough matches. They are:

base_points =

  1.0e+003 *

    1.2550 0.1768
    1.6946 0.2740
    1.3846 0.6210
    1.5280 0.6441
    0.9542 2.1801
    1.3291 2.0505
    1.0098 2.4530
    1.3244 2.8926
    0.4545 1.9488
    0.5378 1.6989
    0.6442 1.4213
    1.4679 1.0281
    1.0560 2.0182
    1.1532 1.7359
    1.3013 1.9071
    1.3707 1.6758

input_points =

  1.0e+003 *

    1.7779 0.3249
    1.3707 0.5978
    1.2735 1.0142
    1.5604 0.5978
    0.9728 2.1431
    1.3198 2.0320
    1.0746 2.5271
    1.3568 2.8972
    0.4499 1.9349
    0.5470 1.6804
    0.6488 1.4028
    1.4818 1.0235
    1.0422 1.9950
    1.1347 1.7036
    1.3059 1.8886
    1.3800 1.5833

Anyone knows why it's giving me the error? It only gives me the
error when I try to fit a 4th Order Polynomial. 2nd and 3rd Order
are fine. Interchanging the input-base points have no effect.

I'd be really greatful if someone could point out what is wrong, or
if someone from mathworks could tell me if the script is buggy and
needs an update.

Thanks,

Jakkris

saka lu

unread,
May 5, 2013, 9:53:07 PM5/5/13
to

Hi Jakkris,

I also got the similar error message "At least 4 non-collinear points needed to infer piecewise linear transform.".. Did you get any idea or solution about this? thanks!!

Saka

"Jakkris Tangkuampien" <ka...@hotmail.com> wrote in message <eea86...@WebX.raydaftYaTP>...

Wennie Tabib

unread,
Feb 14, 2014, 3:26:08 PM2/14/14
to
I am also encountering this error. I have checked that the points I am using are not collinear by taking the slope between each pair of points and checking that the slope between no other two points is the same.

I am trying to geo-reference an image to an orthotile base layer as detailed here: http://www.mathworks.com/help/map/examples/georeferencing-an-image-to-an-orthotile-base-layer.html

When I call

tform = cp2tform(input, spatial, 'projective');

with the following input:

input:
10562.5 1457.5
732 2324
6303.5 4380.5
9456.5 6316.5

spatial:
1334960 633574
1327997.5 635258.5
1331402.5 632587.5
1333092 630489

I see the error "At least 4 non-collinear points needed to infer projective transform."

Not sure what the problem is...

"saka lu" wrote in message <km72e3$moo$1...@newscl01ah.mathworks.com>...

Steven Lord

unread,
Feb 14, 2014, 5:49:31 PM2/14/14
to

"Wennie Tabib" <wta...@andrew.cmu.edu> wrote in message
news:ldlu50$4cp$1...@newscl01ah.mathworks.com...
> I am also encountering this error. I have checked that the points I am
> using are not collinear by taking the slope between each pair of points
> and checking that the slope between no other two points is the same.
> I am trying to geo-reference an image to an orthotile base layer as
> detailed here:
> http://www.mathworks.com/help/map/examples/georeferencing-an-image-to-an-orthotile-base-layer.html
>
> When I call
> tform = cp2tform(input, spatial, 'projective');
>
> with the following input:
> input:
> 10562.5 1457.5
> 732 2324
> 6303.5 4380.5
> 9456.5 6316.5
> spatial:
> 1334960 633574
> 1327997.5 635258.5
> 1331402.5 632587.5
> 1333092 630489
>
> I see the error "At least 4 non-collinear points needed to infer
> projective transform."
>
> Not sure what the problem is...

My background isn't in image processing, but this seems like a mathematical
issue.

Those coordinate values seem rather large, and it looks like they make the
coefficient matrix of the linear system CP2TFORM needs to create to compute
the parameters of the transformation numerically singular. [I suspect
collinear points is the usual reason for that coefficient matrix being
singular, but multiplying large values could do it as well.] You could try
subtracting off the MEAN of the input and spatial coordinates (changing the
origin of your coordinate systems) or simply dividing the values by 1000 or
10000 (essentially, changing the units of your image from meters to
kilometers or tens of kilometers); I tried these out and they seemed to
work. You'd need to apply those transformations and their inverses (adding
the MEAN of the original data or multiplying by 1000 or 10000) when applying
the transformation to other coordinates.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Carlos Ferreira

unread,
Feb 15, 2017, 7:10:08 AM2/15/17
to
"Steven Lord" <Steve...@mathworks.com> wrote in message <ldm6hr$qij$1...@newscl01ah.mathworks.com>...
@Steven Loard

Ok, fine! I use the MEAN of the input and spatial coordinates ; and a 10000 to solve this error. However, the final transformation functional is not the correct. What do i need to do to restore the final function? Was I clear?

Steven Lord

unread,
Feb 15, 2017, 9:14:07 AM2/15/17
to
"Carlos Ferreira" wrote in message <o81ger$s9o$1...@newscl01ah.mathworks.com>...

*snip*

Please don't both post and email me directly. Posting is sufficient.

> Ok, fine! I use the MEAN of the input and spatial coordinates ; and a 10000 to solve this error. However, the final transformation functional is not the correct. What do i need to do to restore the final function? Was I clear?

If you transform a set of data:

x = (1:10).^2;
meanX = mean(x);
stdX = std(x);
xTransform = (x-meanX)./stdX % subtract meanX then divide by stdX

to reverse the transformation just reverse the operations. Mathematically:

xTransform = (x-meanX)./stdX % multiply both sides by stdX to reverse the division
stdX*xTransform = (x-meanX) % then add meanX to both sides to reverse the subtraction
stdX*xTransform+meanX = x

x2 = stdX*xTransform+meanX

The corresponding elements of the variables x and x2 should be very close to one another.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support, use the Contact Us link at the top of http://www.mathworks.com

Carlos Ferreira

unread,
Feb 15, 2017, 11:18:13 AM2/15/17
to
"Steven Lord" wrote in message <o81nnb$e57$1...@newscl01ah.mathworks.com>...
Sorry, I'm new.
I used a polynomial transformation - degree of 2.
As always matlab replies: At least 6 non-collinear points needed to infer polynomial transform.
I tried to subtract the mean of the points.
I get a 'tform' (equation of the transformation) but I don't know how I must transform this with the previous subtraction of the mean in each point.
I think also that 'imwrap' do not support variables like PolynomailTransformation2D.
0 new messages