How can I find out Correlation between two image?

21 Ansichten (letzte 30 Tage)
Syed Zenith Rhyhan
Syed Zenith Rhyhan am 23 Jun. 2019
Bearbeitet: Sampath Gamage am 17 Mär. 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);

Akzeptierte Antwort

Image Analyst
Image Analyst am 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 Kommentare
Image Analyst
Image Analyst am 17 Mär. 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
CORR2 2-D correlation coefficient. R = CORR2(A,B) computes the correlation coefficient between A and B, where A and B are matrices or vectors of the same size. Class Support ------------- A and B can be numeric or logical. R is a scalar double. Example ------- I = imread('pout.tif'); J = medfilt2(I); R = corr2(I,J) See also CORRCOEF, STD2. Documentation for corr2 doc corr2 Other uses of corr2 gpuArray/corr2
help xcorr2
XCORR2 Two-dimensional cross-correlation. XCORR2(A,B) computes the crosscorrelation of matrices A and B. XCORR2(A) is the autocorrelation function. % Example: % Find the cross-correlation of two matrices a = [2 1 5; 3 1 3; 5 2 2]; b = [1 4 3; 2 5 6]; xcorr2(a,b) See also CONV2, XCORR and FILTER2. Documentation for xcorr2 doc xcorr2
Sampath Gamage
Sampath Gamage am 17 Mär. 2023
Bearbeitet: Sampath Gamage am 17 Mär. 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by