alignment of images - is there no function to align control points?

8 visualizaciones (últimos 30 días)
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.
Hello,
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.
Thanks
% example from imwarp
original = imread('cameraman.tif');
imshow(original)
text(size(original,2),size(original,1)+15, ...
'Image courtesy of Massachusetts Institute of Technology', ...
'FontSize',7,'HorizontalAlignment','right')
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);
imshow(distorted)
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
%cpselect(distorted,original,movingPoints,fixedPoints);
tform = fitgeotrans(movingPoints,fixedPoints,'nonreflectivesimilarity');
% step 6
Roriginal = imref2d(size(original));
recovered = imwarp(distorted,tform,'OutputView',Roriginal);
imshowpair(original,recovered,'falsecolor')
Thanks

Respuesta aceptada

Benjamin Thompson
Benjamin Thompson el 16 de Ag. de 2022
Your control points do not match up, and the last control point actually does not appear in the distorted image.
  1 comentario
CompViscount
CompViscount el 17 de Ag. de 2022
You're right about the control points, good spot. Unfortunately it was just a quickly cobbled together example, and that error was not the problem on my own images.
I've worked out the problem in my own images - I was using a cut 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).
I'll mark this as the answer anyways because it fixes the example posted.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by