Laplace算子
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('img/jy3.jpg')
img1 = np.float32(img)
kernel = np.array([[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]])
dst = cv2.filter2D(img1,-1,kernel)
plt.subplot(1,2,1),plt.imshow(img1,'gray')
plt.subplot(1,2,2),plt.imshow(dst,'gray')
cv2.imshow("dst",dst)
cv2.imwrite("ttttt.jpg",dst)
cv2.waitKey(0)
Sobel算子
import cv2
import numpy as np
img=cv2.imread('img\gsyellow_3.jpg')
x=cv2.Sobel(img,cv2.CV_16S,1,0)
y=cv2.Sobel(img,cv2.CV_16S,0,1)
absX=cv2.convertScaleAbs(x)
absY=cv2.convertScaleAbs(y)
dst = cv2.addWeighted(absX,0.5,absY,0.5,0)
cv2.imshow('absX',absX)
cv2.imshow('absY',absY)
cv2.imshow('Result',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
Canny算子
import cv2
import numpy as np
img=cv2.imread('img/gsyellow_3.jpg',0)
img1=cv2.imread('123.jpg')
gray_lap=cv2.Laplacian(img,cv2.CV_16S,ksize=3)
gray_lap1=cv2.Laplacian(img1,cv2.CV_16S,ksize=3)
dst=cv2.convertScaleAbs(gray_lap)
dst1=cv2.convertScaleAbs(gray_lap1)
cv2.imshow('laplacian',dst)
cv2.imshow('laplacian1',dst1)
cv2.imwrite('ttttt_canny1.jpg',dst)
cv2.imwrite('ttttt_canny2.jpg',dst1)
cv2.waitKey(0)
cv2.destroyAllWindows()