How do I use transformPointsForward using a transformation generated by fitgeotrans for a piecewise linear transformation?
Show older comments
I have an optical system that takes input of a square grid of points at the grid vertices (in black) and outputs a distorted grid of slightly displaced points (in red).

I need to map the distorted to the undistored grid so I can place an image point at a location of my chosing in the distorted plane. So if I want to place a spot at x', y' in the distorted plane, I would know what point x, y I should command my system to in the undistorted plane.
I successfully generate the transform using:
tform = fitgeotrans(MovingPoints,FixedPoints,'pwl');
and can invert using:
movingPointsEstimated = transformPointsInverse(tform,FixedPoints)
to compare the distorted grid data to the transformed undestorted grid (red vs. black)

I want to use the forward transformation to provide the undestorted grid point based upon a given distorted grid point. The transformPointsForward command gives an error claiming it is "undefined":
Undefined function 'transformPointsForward' for input arguments of type 'images.geotrans.PiecewiseLinearTransformation2D'.
Doing the tranformation in reverse using the distorted plane as the "fixed" points does not work - complains of foldOverTriangles and bad_triangles.
Answers (2)
I want to use the forward transformation to provide the undestorted grid point based upon a given distorted grid point.
I suspect the reason why a forward transform is not provided is because it is ill-defined for general pwl transforms. In other words, there may be many undistorted grid points that correspond to the same distorted grid point. The messages about bad triangles seems to hint that it is the case for your data as well.
I think you will probably have to choose a different transform type besides 'pwl', but one thing you could try first is to invert numerically,
fun=@(p) norm( transformPointsInverse(tform,p) - distortedPoint)
[undistortedPoint, inversionError] = fminsearch(fun, distortedPoint);
1 Comment
Matt J
on 31 Dec 2019
Abbie's answere relocated as a comment:
Yes, apparently the instructions are vague. Its odd that the transformPointsInverse works but not the Forward transform. Also get an error message saying the transformPointsForward is "undefined" even for the polynomial fit.
Matt J
on 31 Dec 2019
This File Exchange submission might also be worth studying,
It contains many registration tools, but its point_registration() function in particular appears to have an example of how to obtain non-rigid diffeomorphic (i.e., invertible) grid warps,
% Example, 2D Diffeomorphic Warp
% Xstatic=[1 1;
% 1 128;
% 64+32 64
% 64-32 64
% 128 1;
% 128 128];
%
% Xmoving=[1 1;
% 1 128;
% 64-32 64
% 64+32 64
% 128 1;
% 128 128];
% option=struct; options.MaxRef=4;
% sizeI=[128 128];
% [O_trans,Spacing]=point_registration(sizeI,Xstatic,Xmoving,options);
% [O_trans,Spacing]=MakeDiffeomorphic(O_trans,Spacing,sizeI);
%
% Igrid=make_grid_image(Spacing*2,sizeI);
% [Ireg,B]=bspline_transform(O_trans,Igrid,Spacing,3);
% figure, imshow(Ireg)
1 Comment
Abbie Watnik
on 31 Dec 2019
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!