MATLAB: How to evaluate the difference between two images after using CP2TFORM

cp2tformimageImage Processing Toolboxmosaicprocessingr12.1residualswipetransformation

After registering two images together using various transformations, I would first like to be able to determine it they are aligned first, and then determine which transformation (projective, affine, etc ) worked best. I would like to know if there is a function to calculate residuals.
I also would like to know if there is a swipe function where both images are overlapped in one window and a swipe can be done to see if things like the roads line up.
I also would like to know if there is a way to mosaic the final images in one window. ? I also would like to know how they are registered. I need a scientific approach. Looking at them in two separate windows is not much help.

Best Answer

There is no function that can directly calculate residuals or to mosaic images in one window. We do not have a swipe function either.
The workaround is as follows:
To calculate residuals, use the function TFORMFWD on the input_points:
1. Run CPSELECT to get input_points and base_points.
2. Use CP2TFORM to find a transformation structure (tform)
3. Use TFORMFWD on the input_points with the tform from step 2 to get mapped_points
4. Calculate residuals (mapped_points - base_points).
5. Use the residuals to measure the best transformation, or to find poorly picked control points.
An example code is as followed:
cpselect(input_image, base_image)
% user saves control points from File/Save menu
t = cp2tform(input_points,base_points)
% Calculate and plot residuals
mapped points = tformfwd(t,input_points);
residuals = mapped points - base_points;
plot(residuals(:,1),residuals(:,2)), xlabel('x-residuals'), ylabel('y-residuals'), title('Scatter Plot of Residuals')
You can use transparency, which is new as of MATLAB 6.0 (R12), to overlay one image on another. But, first you have to make sure you are using IMTRANSFORM with the appropriate syntax.
In MATLAB 6.1 (R12.1), we do not have specific swipe tools, nor specific mosaicing tools in the toolbox.