位相限定相関法(POC, Phase Only Correlation Method)

V3.0.0
In [29]:
# -*- coding: utf-8 -*-
import cv2
import numpy as np
#Ipythonで表示用の設定
import matplotlib.pyplot as plt
%matplotlib inline

#画像読込
in_img = cv2.imread("lena.jpg", 0)

#平行移動した画像生成(マッチング対象画像):x方向3.3pix, y方向4.6pix
matrix = [[1, 0, 3.3],
          [0, 1, 4.6]]
affine_matrix = np.float32(matrix)
#アフィン変換
afn_img = cv2.warpAffine(in_img, affine_matrix, None, flags=cv2.INTER_CUBIC)

#画素値をfloat型に変換
in_img  = np.float32(in_img)
afn_img = np.float32(afn_img)


#位相限定相関
ret = cv2.phaseCorrelate(in_img, afn_img) 

print "(x_shift, y_shift):", ret[0]
print ret[1],"\n"

#画像表示
plt.figure(figsize=(10,10))
plt.subplot(121)
plt.imshow(in_img,cmap="gray")
plt.title("image1")
plt.subplot(122)
plt.imshow(afn_img,cmap="gray")
plt.title("image2 (shifted image)")
(x_shift, y_shift): (3.3474449727809485, 4.668702388057142)
0.883848486003 


Out[29]:
<matplotlib.text.Text at 0x130d54b0>
inserted by FC2 system