【问题标题】:Finding Hamming distance between 2 threshold image with python用python找到2个阈值图像之间的汉明距离
【发布时间】:2022-01-11 20:27:24
【问题描述】:

我正在做虹膜识别,我有 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)

【问题讨论】:

  • 你能解释一下图像是如何表示的吗?
  • @PresidentJamesK.Polk 这是使用 WARP_POLAR_LINEAR 方法的极坐标图像的阈值。
  • 该图像已损坏。极地经线被赋予了错误的虹膜中心。适当的翘曲会导致直线(圆圈),而不是这个凹凸。 -- 您还应该发布 source 数据而不是过滤后的消化产物,以及多张图片,因为您正在处理 comparison
  • @ChristophRackwitz 我有这个凹凸是因为我删除了瞳孔,我将添加原始图像和我的代码。

标签: python opencv image-processing hamming-distance iris-recognition


【解决方案1】:

我假设您有 2 个阈值图像 imageTH_1imageTH_2,即我们有二进制图像,01 分别代表黑白。

首先flatten 你的图像,所以它们现在是一维数组,

import numpy as np

flat_1 = imageTH_1.flatten()
flat_2 = imageTH_2.flatten()

现在你可以使用Scipy's Hamming distance calculator

from scipy.spatial import distance

ham_dist = distance.hamming(flat_1, flat_2)

【讨论】:

  • 汉明距离似乎不是很精确,因为 2 个相似的图像有 0,2 个非常不同的图像有 30-50,而两个相似但不同的图像有 20-35。
  • 是的,根据我的经验,对图像使用汉明距离非常有限。您可能要考虑使用Structural Similarity Index
  • 我是用 open cv akaze 做到的 :)
【解决方案2】:

以下应该有效: sum(im1 xor im2)

【讨论】:

  • 我有点怀疑 OP 想知道如何使用由 opencv 库表示的图像来做到这一点。
  • 这不是最好的解决方案,因为如果我的两张图像得到以下结果,我会在标准化后尝试使用 Open CV 进行此操作,但现在我需要检查汉明距离以了解虹膜是否相同与否。
  • 可能是“cv::sum(cv::bitwise_xor(im1,im2))”,假设阈值处理产生的像素值为 0 和 1。
  • @MarkLavin 像素为 0 或 255 [[[ 0 0 0] [ 0 0 0] [ 0 0 0] ... [ 0 0 0] [ 0 0 0] [ 0 0 0] ] [[ 0 0 0] [ 0 0 0] [255 255 255] ... [ 0 0 0] [ 0 0 0] [ 0 0 0]] [[ 0 0 0] [ 0 0 0] [ 0 0 0] ... [ 0 0 0] [ 0 0 0] [ 0 0 0]] ... [[255 255 255] [255 255 255] [255 255 255] ... [255 255 255] [255 255 255] [255 255 255]]]
  • "cv::sum(cv::bitwise_xor(im1, im2) / 255)"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-07
  • 2015-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-21
  • 2013-04-22
相关资源
最近更新 更多