imregcorr() misaligns images badly

조회 수: 29 (최근 30일)
Nathan Nguyen
Nathan Nguyen 2024년 7월 3일
댓글: Steve Eddins 2025년 10월 16일 19:08
[tform, peakregcorr] = imregcorr(SourceImageAdj,SourceRef, ...
TargetImageAdj,TargetRef, ...
'transformType', 'similarity', ...
'Window', true);
RegisteredImage = imwarp(SourceImageAdj,SourceRef, tform, 'linear', ...
'OutputView', TargetRef);
disp(peakregcorr)
figure, imshowpair(TargetImageAdj,TargetRef,RegisteredImage, TargetRef)
above is my code to correlate 2 images of different sizes. the goal is to find the correlation between the images to determine what pixel location a point of interest might lie in both images. However, imregcorr consistently misses the mark badly.
Whereas the code above might output a tform object - Dimensionality: 2, Scale: 0.4254, RotationAngle: 2.4851, Translation: [-0.3269 -0.0904]
A more correct tform object (based upon the output image would look like - Dimensionality: 2, Scale: 1, RotationAngle: -1, Translation: [0.0640 0]
The SourceRef and TargetRef seem correct, so Im not sure what is causing the issue
  댓글 수: 3
Nathan Nguyen
Nathan Nguyen 2024년 7월 8일
편집: Nathan Nguyen 2024년 7월 8일
these are the input images that I am using
srcimg - source image
srcref - source reference imref2d
targetim - target image
tgtref - target reference imref2d
tform - transformation object that is formed from the images
The problem is that my original source image is 512x512 whereas the target image is 2048x2044
Steve Eddins
Steve Eddins 2025년 10월 16일 19:08
See my answer below, or my 16-Oct-2025 blog post, for updated information related to releases R2024b and later.

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

채택된 답변

Matt J
Matt J 2024년 7월 8일
편집: Matt J 2024년 7월 8일
Phase correlation isn't going to be a good algorithm for images of a starry field. I think your best bet is to do landmark extraction -- either manually with cpselect or automatically if you have some way to do that -- and then use fitgeotform2d.
[sp,tp] = cpselect(SourceImageAdj, TargetImageAdj ,'Wait',true);
[sp(:,1), sp(:,2)]=intrinsicToWorld(SourceRef, sp(:,1), sp(:,2))
[tp(:,1), tp(:,2)]=intrinsicToWorld(TargetRef, tp(:,1), tp(:,2))
tform = fitgeotform2d(sp,tp,'similarity')
RegisteredImage = imwarp(SourceImageAdj,SourceRef, tform, 'linear', ...
'OutputView', TargetRef);
figure, imshowpair(TargetImageAdj,TargetRef,RegisteredImage, TargetRef)
  댓글 수: 2
Nathan Nguyen
Nathan Nguyen 2024년 7월 9일
편집: Matt J 2024년 7월 9일
Thanks yeah manual selection seems to work well!
This isn't relevant to the question specifically but if I found all of the feature detection algorithms from matlab on this webpage. These seems to be pretty useful https://www.mathworks.com/help/images/techniques-supported-by-registration-estimator-app.html
Steve Eddins
Steve Eddins 2025년 10월 16일 19:08
See my answer below, or my 16-Oct-2025 blog post, for updated information related to releases R2024b and later.

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

추가 답변 (1개)

Steve Eddins
Steve Eddins 2025년 10월 16일 19:06
As of R2024b, the function imregcorr uses a new algorithm called normalized gradient correlation. See my 16-Oct-2025 blog post for more information. The function can now register these star-field images successfully.
load srcimg SourceImageAdj
load srcref.mat SourceRef
load targetim.mat TargetImageAdj6
load tgtref.mat TargetRef
tform = imregcorr(SourceImageAdj, SourceRef, ...
TargetImageAdj6, TargetRef, ...
TransformType = "similarity")
tform =
simtform2d with properties: Dimensionality: 2 Scale: 0.9981 RotationAngle: -1.0487 Translation: [0.0617 -0.0056] R: [2×2 double] A: [ 0.9979 0.0183 0.0617 -0.0183 0.9979 -0.0056 0 0 1.0000]
registered_image = imwarp(SourceImageAdj, SourceRef, tform, "linear", ...
OutputView = TargetRef);
imshowpair(TargetImageAdj6, TargetRef, registered_image, TargetRef)

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by