File Exchange

image thumbnail

Preprocess CP2TFORM

version (1.98 KB) by Dirk-Jan Kroon
Removes folded over triangles in piecewise linear image transformation, so cp2tform always works.

1 Download

Updated 17 Mar 2010

View License

When CP2TFORM is used in piecewise linear image transformation mode, it uses triangulation to calculate the local image transformation. Sometimes a good triangulation of basepoints gives folded triangles when used with the input points. The function CP2TFORM try's to remove the controlpoints causing the folding, but often fails with the error:

Eliminated * control point pair(s).
Fold-over triangles remain. See CP2TFORM reference page.

This function PreProcessCp2tform removes all control points which cause fold-over triangles with cp2tform.

example code :
xy=[input_points2(:,2) input_points2(:,1)];
uv=[base_points2(:,2) base_points2(:,1)];
[xy uv]=PreProcessCp2tform(xy,uv);
trans_prj = cp2tform(xy,uv,'piecewise linear');
J = imtransform(I,trans_prj,'Xdata',[1 100],'YData',[1 100],'XYscale',1);

Cite As

Dirk-Jan Kroon (2020). Preprocess CP2TFORM (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Vuong Le

Thanks for the nice tool.
I got a small problem with it when the two triangles are very thin and folded, then it couldn't remove it.
I fixed it by replacing your FindUpsideDown(xy,uv,tri) by FindInsideOut(xy,uv,tri); doing it twice before calling cp2tform, then things are fine.
I am sorry I haven't look in details of the two functions to find the difference.
Doing it twice did help, though, since the new mesh can still have error. (How many times should it be called to make sure the mesh is good?)

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux