如何找到灰度图像的相关性 [英] How to find Correlation of a grayscale image

查看:277
本文介绍了如何找到灰度图像的相关性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个固定尺寸为256 * 256的图像A.我能够找到水平和垂直相邻像素之间的相关性.但是我不知道如何从图像中随机选择4096对两个对角线相邻的像素,计算它们的相关系数,然后绘制这些对角线相邻像素的分布.

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(:));

使用相同的算法对彩色和灰度图像进行加密.对于彩色图像,它将分别应用于RGB平面,并且仅应用于灰度一次.在彩色图像的情况下,对角相关系数几乎为零.在灰度下,我想知道在计算相关系数时是否出错.

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.

推荐答案

(这最初是在(我的)评论中,但实际上是答案.我将其变成可以接受的实际答案.建议在例如 https://meta .stackexchange.com/questions/54718/如何处理问题(在评论中得到回答.)

(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

xed = A(1:end-1,1:end-1);

名称分别为xedyed,但使用方式如下

with names xed and yed, but used like this

xRand = xod(randIndex);

名称为xodyod

.大概您在其他地方用这些名称定义了其他变量,这就是为什么您的代码执行错误操作而不是因出现明显错误而失败的原因.

with names xod and yod. 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 :-).

这篇关于如何找到灰度图像的相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆