Running tforminv using a loaded TFORM structure

Viewed 35

I use cp2tform and a set of about 100 xy control point pairs to generate a TFORM structure, which I then use to transform xy coordinates between two coordinate systems ("old" and "new"). It works fine. Below is how I convert coordinates x_old y_old into x_new y_new.

[TFORM]= cp2tform([x2,y2],[x1,y1],'lwm',16);
[x_new, y_new] = tforminv(TFORM, x_old,y_old);

Now I need to save the TFORM structure into a mat file, and load it to do my transforms from old to new, without having to run cp2tform each time. When loaded, the TFORM structure appears to contain all the data needed for the transform (control points etc). However, I get the following error when running tforminv:

Error using feval
Undefined function handle.

Error in tform (line ...)
X = feval( t.(f.fwd_fcn), U, t );

Error in tforminv (line ...)
varargout = tform('inv', nargout, varargin{:});

I found a post recommending including cp2tform into the function file.

%#function cp2tform

Tried this, but it did not have an effect. There was a warning about not being able to load it which is strange, as I run cp2tform fine from my local directory just fine.

I can go back to running cp2tform each time, but I wonder if there is a way to use preprocessed data in the TFORM structure. May I ask for help?

Thank you in advance!

0 Answers
Related