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

조회 수: 6 (최근 30일)
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

채택된 답변

Benjamin Thompson
Benjamin Thompson 2022년 8월 16일
Your control points do not match up, and the last control point actually does not appear in the distorted image.
  댓글 수: 1
CompViscount
CompViscount 2022년 8월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by