There is an image A of fixed size 256*256. I am able to find correlation between horizontally and vertically adjacent pixels. But I am not understanding how exactly to randomly select 4096 pairs of two diagonally adjacent pixels from the image, calculate their correlation co-efficient and then plot the distribution of these diagonally adjacent pixels.
xed = A(1:end-1,1:end-1); % All but the last row and column
yed = A(2:end,2:end); % All but the first row and column
randIndex = randperm(numel(xed)); % A random permutation of the integers from 1 to numel(x)
randIndex = randIndex(1:4096); % Pick the first 4096 indices
xRand = xod(randIndex); % 4096 random values from x
yRand = yod(randIndex); % The corresponding 4096 values from y
% Compute the Correlation coefficient of x and y
red_xy = corrcoef(xRand(:),yRand(:));
Same algorithm is used to encrypt both color and grayscale images. For color images it is applied to RGB planes separately and for grayscale only once. Diagonal correlation coefficient almost zero is obtained in case of color image. In grayscale I want to know if I am going wrong in calculating correlation coefficient.
(This was originally in (my) comments, but turns out actually to be the answer. I'm making it into an actual answer that can be accepted as recommended at, e.g., https://meta.stackexchange.com/questions/54718/how-to-handle-questions-which-are-answered-in-the-comments.)
The problem is that your partial arrays are defined like this
with names
xed
andyed
, but used like thiswith names
xod
andyod
. Presumably you have other variables, defined elsewhere, with those names, which is why your code does something wrong instead of failing with an obvious error.There's a more general moral here: you can reduce the risk of this kind of error by giving your variables longer, more informative and more distinctive names that can't be turned into one another by single-character typos :-).
I hope that is true, and everyone is helpful. I'm sorry for my English.