alignment of images - is there no function to align control points?
9 views (last 30 days)
EDIT: the issue I was having is actually due to using a partial image to select the control points and calculate transform, but then using that transform on the full image. I wouldn't have thought it made a difference but obviously it does (must be something do with axis of rotation moving).
So this question is a waste of time as the issue is not contained in the example, and the example had it's own error. Apologies! Doesn't explain why imregcorr and imregister gave such awful results, as I was using full images for those... But I have no desire to revisit the frustration today.
I am trying to align some images so that I can do some pixel-wise comparison. There are ~10000 very consistent images of components, but there is a small variation in position in the rig, hence the desire to align. I started using "smart" inbuilt functions (imregister, imregcorr) and have progressively pared my expectations all the way back to an approach so simple I can't understand why it isn't possible - I should have just done the maths myself at this point! So, my current approach is to pick 2 control points as per this example:
And do a basic transform using fitgeotrans.
However, when I superimpose these two images using imshowpair 'falsecolor'... the control points are not on top of eachother. The images match scale/rotation but there is no translation. To me, this means they aren't fully aligned...? I realise it says "rotation and scale" in fitgeotrans, but this is a tutorial from this page which is about alignment and registration:
I see no option for translation, and don't understand why translation wouldn't be part of the same function... and I can't find any function that would just do the translation as a 2nd step.
I can't share my images so I've made an equivalent problem from one of the tutorials, copied below. As you can see in the final figure, the images are matching rotation/scale but not translation, so they can't be used for pixel-wise comparison, superimposing or "average" image creation. Hopefully I'm missing something silly and there's existing functionality for this.
% example from imwarp
original = imread('cameraman.tif');
'Image courtesy of Massachusetts Institute of Technology', ...
scale = 1;
distorted = imresize(original,scale); % Try varying the scale factor.
theta = 5;
distorted = imrotate(distorted,theta); % Try varying the angle, theta.
distorted = distorted(1:200,1:190);
fixedPoints = [33.3750 105.8750; 169.6250 75.8750; 134.8750 200.1250];
movingPoints = [37.9375 112.0625; 158.5625 75.4375; 136.3125 188.8125];
%% code for picking control points
tform = fitgeotrans(movingPoints,fixedPoints,'nonreflectivesimilarity');
% step 6
Roriginal = imref2d(size(original));
recovered = imwarp(distorted,tform,'OutputView',Roriginal);