python - 两个二值图像之间的相关性

标签 python image-processing correlation

我需要在Python中计算两个二值图像之间的相关性。如果矩阵相同,则脚本应返回 1;如果完全不相关,则脚本应返回 0。它应该类似于 Matlab 中的 corr2 ( http://www.mathworks.se/help/images/ref/corr2.html )。这是我正在使用的测试:

import numpy as np
from scipy import signal

A = np.matrix('1 0; 1 0')
B = np.matrix('1 0; 1 0')
cor = signal.correlate2d(A, B)
print cor

如何获得单个值而不是矩阵?

最佳答案

尝试corrcoef。它将返回一个 2*2 矩阵,两个矩阵之间的非对角元素相关系数:

import numpy as np
A = np.matrix('1 1; 1 0')
B = np.matrix('1 0; 1 0')
cor = np.corrcoef(A.reshape(-1), B.reshape(-1))[0][1]
print cor

关于python - 两个二值图像之间的相关性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21530615/

相关文章:

python - 使用 AST 和 Tree walker 来翻译 DSL,而不是直接从解析器语法解析和翻译对象,有什么优点?

c++ - 使用 reshape 乘以 Mat 矩阵,OpenCV 中的 Mat 类型问题

python - 为什么相关矩阵的列小于 pandas Dataframe 的列

r - 在两个矩阵上使用 'apply' 而不是嵌套循环

python - 视频流变得失真的QImage

python - 为什么我在 Django 示例教程中出现 Python 缩进错误

python - 如何使用Python SDK在Azure数据工厂中的特定分支下运行管道?

java - BufferedImage 类型中的方法 getRGB(int, int) 不适用于参数 (..)

c# - C# 中的图像处理

python - Pandas DataFrame 列与自定义函数的成对相关