我正在做虹膜識別,我有 2 個虹膜閾值影像。如何使用 Python 在 2 個影像之間計算漢明距離?謝謝

這里你有極坐標變換之前的原始影像:

和代碼:
img_crop1 = cv.imread('crop_1.png')
polar_img = cv.warpPolar(
img_crop1, (256, 1024), (self.iris_1[0], self.iris_1[1]), self.iris_1[2] * 2, cv.WARP_POLAR_LINEAR)
# Rotate it sideways to be more visually pleasing
polar_img = cv.rotate(polar_img, cv.ROTATE_90_COUNTERCLOCKWISE)
# crop image
polar_img = polar_img[int(polar_img.shape[0] / 2)
: polar_img.shape[0], 0: polar_img.shape[1]]
polar_img = cv.cvtColor(polar_img, cv.COLOR_BGR2GRAY)
_, threshold = cv.threshold(polar_img, 100, 255, cv.THRESH_BINARY)
cv.imwrite("foreground.png", threshold)
uj5u.com熱心網友回復:
我會假設你有2倍閾值處理的影像imageTH_1和imageTH_2這是我們擁有的二進制影像,0和1分別代表黑白。
首先將您的影像展平,使它們現在是一維陣列,
import numpy as np
flat_1 = imageTH_1.flatten()
flat_2 = imageTH_2.flatten()
現在您可以使用Scipy 的漢明距離計算器
from scipy.spatial import distance
ham_dist = distance.hamming(flat_1, flat_2)
uj5u.com熱心網友回復:
以下應該有效: sum(im1 xor im2)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/386696.html
標籤:Python opencv 图像处理 汉明距离 虹膜识别
上一篇:將枕頭影像轉為灰度的伽馬校正
