def compute_PCC(A, B, masks=None):
"""Computes the Pearson product-moment correlation coefficients (PCC) for
the two images.
Parameters
-------------
A,B : ndarray
The two images to be compared
masks : list of ndarrays, optional
If supplied, the data under each mask is computed separately.
Returns
----------------
covariances : array, list of arrays
"""
covariances = []
if masks is None:
data = np.vstack((np.ravel(A), np.ravel(B)))
return np.corrcoef(data)
for m in masks:
weights = m[m > 0]
masked_B = B[m > 0]
masked_A = A[m > 0]
data = np.vstack((masked_A, masked_B))
# covariances.append(np.cov(data,aweights=weights))
covariances.append(np.corrcoef(data))
return covariances
评论列表
文章目录