当前位置:   article > 正文

基于灰度方差的指纹图像分割方法python_指纹分割 python

指纹分割 python

基于灰度方差的指纹图像分割方法python

import copy
import math

import cv2
import numpy as np

# 基于灰度方差的指纹图像分割方法,8×8小块
img = cv2.imread('021_9_2.png')  # 读取图片
img_0 = img[:, :, 0]  # 取图像中的一个通道
W = 8  # 小块的尺寸
row = img_0.shape[0]
col = img_0.shape[1]
num_row_W = math.ceil(row / W)
num_col_W = math.ceil(col / W)
Var = np.empty((num_row_W, num_col_W))  # 方差矩阵
for i in range(0, row, W):
    for j in range(0, col, W):
        row_var = int(i / W)
        col_var = int(j / W)
        r_row = min(i + W, row)
        r_col = min(j + W, col)
        tmp = img_0[i:r_row, j:r_col]
        M = np.sum(tmp) / (r_row - i) / (r_col - j)  # 计算小块平均值
        tmp = tmp - M
        Var[row_var, col_var] = np.sum(tmp * tmp) / (r_row - i) / (r_col - j)  # 计算方差

threshold = 100  # 阈值为100,根据不同指纹图像设置
img_cut = copy.deepcopy(img)
# 将方差小于阈值的方块置为0
for i in range(0, row, W):
    for j in range(0, col, W):
        row_var = int(i / W)
        col_var = int(j / W)
        if Var[row_var, col_var] < threshold:
            img_cut[i:min(i + W, row), j:min(j + W, col), :] = 0

# 寻找指纹的矩形边界
min_row = 10000
max_row = -1
min_col = 10000
max_col = -1
for i in range(0, row, W):
    for j in range(0, col, W):
        if img_cut[i, j, 0] != 0:
            min_row = min(i, min_row)
            max_row = max(i, max_row)
            min_col = min(j, min_col)
            max_col = max(j, max_col)
im = img[min_row:max_row, min_col:max_col, :]  # 原指纹图像切割
im_cut = img_cut[min_row:max_row, min_col:max_col, :]  # 指纹图像空白区域置0切割

cv2.imshow('im', im)
cv2.waitKey(0)
cv2.destroyAllWindows()

cv2.imshow('im_cut', im_cut)
cv2.waitKey(0)
cv2.destroyAllWindows()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

原指纹图像:
指纹图像
原指纹图像切割:
指纹图像空白区域置0切割
指纹图像空白区域置0切割:
指纹图像空白区域置0切割

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/346706
推荐阅读
相关标签
  

闽ICP备14008679号