图像梯度
作者:互联网
from imutils import * image = imread('image/bricks.png') show(image) def gradient(image): image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) # cv2.CV_64F输出图像的深度(数据类型),64位float类型,因为梯度可能是正也可能是负 laplacian = cv2.Laplacian(image, cv2.CV_64F) # 1, 0表示在x方向求一阶导数,最大可以求2阶导数 sobelx = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=3) # 0, 1表示在y方向求一阶导数,最大可以求2阶导数 sobely = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=3) titles = ['Original', 'Laplacian', 'SobelX', 'SobelY'] images = [image,laplacian,sobelx,sobely] plt.figure(figsize=(10,5)) for i in range(4): plt.subplot(2,2,i+1) plt.imshow(images[i],'gray') plt.title(titles[i]) plt.axis('off') plt.show() gradient(image)
标签:plt,导数,64F,梯度,image,cv2,图像,CV 来源: https://www.cnblogs.com/yunshangyue71/p/13584416.html