from skimage.color import rgb2gray
from skimage.io import imread
import numpy as np
from skimage.morphology import binary_opening,\
binary_closing, disk, binary_erosion, binary_dilation, square
import matplotlib.pyplot as plt
im = rgb2gray(imread('./9781789343731_Code/images/fingerprint.png'))
im[im <= 0.5] = 0
im[im > 0.5] = 1
im_o = binary_opening(im, square(6))
im_c = binary_closing(im, square(6))
im_oc = binary_closing(binary_opening(im, square(6)), square(6))
im_co = binary_opening(binary_closing(im, square(6)), square(6))
plt.gray()
plt.figure(figsize=(20,20))
plt.subplot(231)
plt.imshow(im)
plt.title('original', size=20)
plt.axis('off')
plt.subplot(232)
plt.imshow(im_o)
plt.title('opening', size=20)
plt.axis('off')
plt.subplot(233)
plt.imshow(im_c)
plt.title('closing', size=20)
plt.axis('off')
plt.subplot(234)
plt.imshow(im_oc)
plt.title('opening + closing', size=20)
plt.subplot(235)
plt.imshow(im_co)
plt.title('closing + opening', size=20)
plt.axis('off')
plt.savefig('finger.jpg')
plt.show()
python利用开闭运算实现指纹清洗
最新推荐文章于 2024-10-20 03:15:28 发布
这段代码演示了如何使用Python的skimage库进行图像处理,具体涉及将彩色图像转换为灰度,然后应用形态学操作如开运算、闭运算来增强指纹图像的清晰度。最终结果显示了原始图像和经过不同形态学操作后的图像,有助于指纹识别。
摘要由CSDN通过智能技术生成