How can I find out Correlation between two image?
18 views (last 30 days)
Show older comments
Syed Zenith Rhyhan
on 23 Jun 2019
Edited: Sampath Gamage
on 17 Mar 2023
clc;
clear all;
close all;
a=imread('1.jpg');
b=imread('2.jpg');
corr2(a,b);
____________::Error Occured::_____________
Error using corr2
Error using corr2
Expected input number 1, A, to be two-dimensional.
Error in corr2>ParseInputs (line 35)
validateattributes(A, {'logical' 'numeric'}, {'real','2d'}, mfilename, 'A', 1);
Error in corr2 (line 21)
[a,b] = ParseInputs(varargin{:});
Error in featureExt (line 9)
corr2(a,b);
0 Comments
Accepted Answer
Image Analyst
on 23 Jun 2019
They're probably color. Do it on one color channel at a time, or use rgb2gray() to convert them to grayscale. Untested code:
grayImage1 = rgb2gray(a);
grayImage2 = rgb2gray(b);
out = corr2(grayImage1, grayImage2);
4 Comments
Image Analyst
on 17 Mar 2023
@Sampath Gamage what do you mean by the correlation matrix? If you use corr2() that basically says how much does each pixel's value move in tandem between the two images? It's a single scalar. If you use xcorr2() you will get an image that is the sum of the two image widths and it is the cross correlation of the two images.
help corr2
help xcorr2
Sampath Gamage
on 17 Mar 2023
Edited: Sampath Gamage
on 17 Mar 2023
@Image Analyst, Thanks for the reply!
I think this is not just coding anymore. :) I'm trying to understand how to find the correlation of two images and how to present the result.
If we have two images of same size, (say 50x50 px) can we create a correlation map of 50x50 that gives the correlation of each pixel?
Or is the correlation between two images simply given by a single number?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!