import cv2 import numpy as np #加载图像 image = cv2.imread('C:/test.jpg') #自定义卷积核 kernel_sharpen_1 = np.array([ [-1,-1,-1], [-1,9,-1], [-1,-1,-1]]) kernel_sharpen_2 = np.array([ [1,1,1], [1,-7,1], [1,1,1]]) kernel_sharpen_3 = np.array([ [-1,-1,-1,-1,-1], [-1,2,2,2,-1], [-1,2,8,2,-1], [-1,2,2,2,-1], [-1,-1,-1,-1,-1]])/8.0 #卷积 output_1 = cv2.filter2D(image,-1,kernel_sharpen_1) output_2 = cv2.filter2D(image,-1,kernel_sharpen_2) output_3 = cv2.filter2D(image,-1,kernel_sharpen_3) #显示锐化效果 cv2.imshow('Original Image',image) cv2.imshow('sharpen_1 Image',output_1) cv2.imshow('sharpen_2 Image',output_2) cv2.imshow('sharpen_3 Image',output_3) #停顿 if cv2.waitKey(0) & 0xFF == 27: cv2.destroyAllWindows()
OPenCV 图像锐化处理
最新推荐文章于 2024-09-09 17:09:11 发布