correlation between two images

5 views (last 30 days)
Joseph Tabbah
Joseph Tabbah on 23 Nov 2022
Answered: Image Analyst on 23 Nov 2022
i need to find the corrolation between 2 greyscale images and see if the signals are similar
RGB = imread('tree.jpg');%read first image
imshow(RGB)
RGB2 = imread('white horse.jpg');%read second image
imshow(RGB2)
I1 = rgb2gray(RGB);% we convert images to greyscale
figure
imshow(I1)
I2 = rgb2gray(RGB2);% we convert images to greyscale
figure
imshow(I2)
subplot(2, 1, 2);
F=fft2(I1);
S1=fftshift(log(1+abs(F)));% we convert first image to frequency domain
imshow(S,[]);
%we found the centred specturm and applied the log transform in the same
%step
%this could also be done in 2 steps as follows:
%F1 = fft(I1);
% centered spectrum
%S= fftshift(F!);
% log transform
%S1 = log(1+abs(S));
subplot(2, 1, 2);
F2=fft2(I2);
S2=fftshift(log(1+abs(F2)));%convert second image to frequency domain
imshow(S,[]);
% now we check the lengh of the signals and we compare them
len=length(I1);
len2 = length(I2);
if len>len2
S4=resample(S1,len1,len2);
end
if len<len2
S5=resample(S2,len1,len2);
end
% we make the images of the same size to be able to compare them using
% correlation
[acorrX,lagX]=xcorr(S4,S5);
figure;
plot(lagX,corrX);title('Correlation between 2 signals');
figure;
plot(lagX2,acorrX2);title('Correlation between signal and itself');
p=abs(acorrX-acorrX2);
matlab keeps telling me variable s4 not recognised, does anyone know the problem?

Answers (1)

Image Analyst
Image Analyst on 23 Nov 2022
You never assigned S4 because you never went into the if block, which means len is not greater than len2.
You need to learn how to step through your code to debug it. You won't get far in MATLAB without knowing that. So invest a few minutes here:

Categories

Find more on Image Processing Toolbox 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!