# How to calculate the correlation coefficient in an image?

19 Ansichten (letzte 30 Tage)
Abirami am 2 Nov. 2014
Beantwortet: Ranjit Shrestha am 31 Jan. 2022
In order to find the correlation between two adjacent pixels (horizontal, vertical and diagonal), I have randomly selected 3000 pairs of adjacent pixels from the original and encrypted images. I used the inbuilt MATLAB function corrcoef but I'm not getting the result. Do I need to find the mean, variance and covariance of the pixels before calculating the correlation coefficient?If I do where do I use it in the function? This function doesnt seem to use any of the values. I used the following code to calculate for horizontally adjacent pixels
m1 = A(:,1:end-1,1); %# All rows and columns 1 through 255
n1 = A(:,2:end,1); %# All rows and columns 2 through 256
% A is the original image
randIndex1 = randperm(numel(m1)); %# A random permutation of the integers
%# from 1 to numel(m1)
randIndex1 = randIndex1(1:3000); %# Pick the first 3000 indices
m1Rand = m1(randIndex1); %# 3000 random values from m1
n1Rand = n1(randIndex1); %# The corresponding 3000 values from n1
r_mn1 = corrcoef(m1Rand(:),n1Rand(:)); disp('r_mn1=');disp(r_mn1);
I do have the formulas for calculating mean, variance, covariance and correlation coefficient.I want to know whether the inbuilt function can be used in this case or should I calculate using the formulas? Please help. Thanks in advance.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

Ali Broumandnia am 11 Jan. 2017
Bearbeitet: Walter Roberson am 29 Apr. 2018
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
x1 = double(P(:,1:end-1));
y1 = double(P(:,2:end));
randIndex1 = randperm(numel(x1));
randIndex1 = randIndex1(1:3000);
x = x1(randIndex1);
y = y1(randIndex1);
r_xy = corrcoef(x,y);
scatter(x,y);
xlabel('Pixel gray value on location (x,y)')
ylabel('Pixel gray value on location (x+1,y)')
end
##### 2 KommentareKeine anzeigenKeine ausblenden
Wisal Adnan am 6 Jun. 2021
hello Ali
i am using this code put how can calcalate corr in direction ( hor.,ver.,dig.)
Thanks
Abubakar Abba am 22 Sep. 2021
Hello, @Wisal Adnan Have you done the calculation for Hori Corr?

Melden Sie sich an, um zu kommentieren.

Ranjit Shrestha am 31 Jan. 2022
what if we have more than two images? I mean a sequence of images.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Image Category Classification finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by