Pythonはnumpyを用いて画像の相関係数を計算する(相関解析)
923 ワード
# -*- coding: utf-8 -*-
'''
Created on 2018-9-7 16:23:25
@author: skyblue
'''
import cv2
import numpy as np
img0 = cv2.imread('./imagesTest4/0.png', cv2.IMREAD_GRAYSCALE)
img1 = cv2.imread('./imagesTest4/1.png', cv2.IMREAD_GRAYSCALE)
cv2.imshow('img0', img0)
cv2.imshow('img1', img1)
img0= img0.reshape(img0.size, order='C') # 。 ,
img1= img1.reshape(img1.size, order='C')
#
'''
;
, results[i][j] i j .
np.corrcoef ( list) (coefficient)
, (2*2 ) , 1, 。
"[0, 1]" 0 coefficient
'''
print("Correlation coefficient of image 0 and image 1: %f
" % np.corrcoef(img0, img1)[0, 1])
# cv2.waitKey(0)
cv2.destroyAllWindows()