轮廓内核处理

2022-05-29 10:07:14 浏览数 (1)

代码语言:javascript复制
import cv2
import imageio
import numpy as np
import matplotlib.pyplot as plt
from skimage import color
from skimage import exposure
from scipy.signal import convolve2d
img=cv2.imread('C:/Users/xpp/Desktop/Lena.png')
img=color.rgb2gray(img)  
sharpen_kernel=np.array([[0,-1,0],
                        [-1,5,-1],
                        [0,-1,0]])
image_sharpen=convolve2d(img, sharpen_kernel,mode='valid')
edge_kernel=np.array([[-1,-1,-1],
                     [-1,8,-1],
                     [-1,-1,-1]])
edges=convolve2d(image_sharpen, edge_kernel,mode = 'valid')
blur_kernel=np.array([[1,1,1],
                     [1,1,1],
                     [1,1,1]])/9.0;
denoised=convolve2d(edges, blur_kernel,mode='valid')
denoised_equalized=exposure.equalize_adapthist(denoised/np.max(np.abs(denoised)),
                                                 clip_limit=0.03)
plt.figure(figsize=(5,5))
plt.imshow(denoised_equalized, cmap='gray')    
plt.axis('off')
plt.show()

算法:轮廓内核处理是突出显示像素值之间的差异,亮度接近的相邻像素旁边的像素在新图像中将显示为黑色,而差异性较大的相邻像素的旁边像素将显示为白色。

0 人点赞