Problem figuring out shift in image

I have shifted the first image (scroll_init) slightly to scroll_fin and am using 2-D cross correlation to figure out the difference.
My code is :
sc_in = imread('C:\Users\Harshil\Desktop\SURA\Resources\scroll_init.png');
sc_in = double(rgb2gray(sc_in));
sc_fin = imread('C:\Users\Harshil\Desktop\SURA\Resources\scroll_fin.png');
sc_fin = double(rgb2gray(sc_fin));
cc = xcorr2(sc_fin,sc_in);
[max_cc, imax] = max(abs(cc(:)));
[ypeak, xpeak] = ind2sub(size(cc),imax(1));
figure
plot(cc(:))
title('Cross-Correlation')
hold on
plot(imax,max_cc,'or')
hold off
text(imax*1.05,max_cc,'Maximum')
corr_offset = [(ypeak-size(sc_in,1)) (xpeak-size(sc_in,2))];
disp(corr_offset);
But, I am getting the shift as [0 0]. The plot is :
Can someone please tell how to get the correct shift?

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by