imregcorr() misaligns images badly
Show older comments
[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 Comments
Garmit Pant
on 4 Jul 2024
Hello
Can you please provide the input images that you are using?
Regards
Nathan Nguyen
on 8 Jul 2024
Edited: Nathan Nguyen
on 8 Jul 2024
Steve Eddins
on 16 Oct 2025
See my answer below, or my 16-Oct-2025 blog post, for updated information related to releases R2024b and later.
Accepted Answer
More Answers (1)
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")
registered_image = imwarp(SourceImageAdj, SourceRef, tform, "linear", ...
OutputView = TargetRef);
imshowpair(TargetImageAdj6, TargetRef, registered_image, TargetRef)
Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
