Matlab 显著性检测模型性能度量线性相关系数 CC

% created: Zoya Bylinskii, Aug 2014

% This finds the linear correlation coefficient between two different 
% saliency maps (also called Pearson's linear coefficient).
% score=1 or -1 means the maps are correlated
% score=0 means the maps are completely uncorrelated

function score = CC(saliencyMap1, saliencyMap2)
% saliencyMap1 and saliencyMap2 are 2 real-valued matrices

map1 = im2double(imresize(saliencyMap1, size(saliencyMap2)));
map2 = im2double(saliencyMap2);
% map1=saliencyMap1;
% map2=saliencyMap2;

% normalize both maps
map1 = (map1 - mean(map1(:))) / std(map1(:)); 
map2 = (map2 - mean(map2(:))) / std(map2(:)); 

score = corr2(map2, map1);
function r = corr2(varargin)

[a,b] = ParseInputs(varargin{:});

a = a - mean2(a);
b = b - mean2(b);
r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

%--------------------------------------------------------
function [A,B] = ParseInputs(varargin)

narginchk(2,2);

A = varargin{1};
B = varargin{2};

validateattributes(A, {'logical' 'numeric'}, {'real','2d'}, mfilename, 'A', 1);
validateattributes(B, {'logical' 'numeric'}, {'real','2d'}, mfilename, 'B', 2);

if any(size(A)~=size(B))
    error(message('images:corr2:notSameSize'))
end

if (~isa(A,'double'))
    A = double(A);
end

if (~isa(B,'double'))
    B = double(B);
end




关键代码:

a = a - mean2(a);
b = b - mean2(b);
r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

可以用公式表示,图a,b的相关性大小,越大越相关:

方差 :

D(x) = \frac{1}{mn} \sum_{i=1}^m \sum_{j=1}^n (x_{ij} - u_x)^2

协方差:

cov(x,y) = \frac{1}{mn} \sum_{i=1}^m \sum_{j=1}^n (x_{ij}-u_x) (y_{ij}-u_y)

线性相关系数 CC:

CC = {\color{Red} \frac{cov(x, y)} {\sqrt{cov(x,x)} \sqrt{cov(y,y)}}} = \frac{cov(x, y)}{ \sqrt{D(x)} \sqrt{D(y)}}

其中,u为均值。即为:x 和 y 的方差,除以 x 的标准差与 y 的标准差之积,CC越大越相关。

1)如果 x 等于 y,由公式红色部分可知 CC = 1,最相关;

2)而当x 完全不等于 y,即 x 独立于 y,则由下面公式:

cov(x, y) = E(x y) - E(x) E(y)

其中E为期望,即均值。当 x 独立于 y,则 :E(x y) = E(x) E(y),所以cov(x, y)就为0,CC值为0,最不相关。

 

 

 

 

阅读更多

没有更多推荐了,返回首页