Operator image gradient -Sobel
Gx Gy is equal to the right of the left minus minus can be equal to the pixel value
= cv2.Sobel DST (the src, ddepth, DX, dy, ksize)
- ddepth: depth of the image
- dx and dy represent the horizontal and vertical directions
- ksize Sobel operator is size
CV2 Import
Import numpy AS NP
IMG cv2.imread = ( "D: /pie.png")
sobelx = cv2.Sobel (IMG, cv2.CV_64F, 1,0, ksize =. 3) Test # horizontal direction only
sobelx1 = cv2 .convertScaleAbs (sobelx)
RES = np.hstack ((sobelx, sobelx1))
cv2.imshow ( 'erosion', RES)
cv2.waitKey (0)
cv2.destroyAllWindows ()
# is a positive number of white to black, black to white is negative All negative numbers will have to be truncated to 0, so the absolute value
Adding xy image image gradient
Import CV2 Import numpy AS NP IMG = cv2.imread ( " D: /pie.png " ) sobelx = cv2.Sobel (IMG, cv2.CV_64F, 1,0, ksize =. 3) # test only horizontal direction sobely = cv2 .Sobel (IMG, cv2.CV_64F, 0,1, ksize =. 3) # test only horizontal direction sobely1 = cv2.convertScaleAbs (sobely) sobelx1 = cv2.convertScaleAbs (sobelx) soblexy = cv2.addWeighted (sobelx1,0.5, sobely1 , 0.5 , 0) cv2.imshow ( ' erosion ' , soblexy) cv2.waitKey (0) cv2.destroyAllWindows ()
The image gradient can be calculated laplacian algorithm images directly
Import CV2 Import numpy AS NP IMG = cv2.imread ( " D: /pie.png " ) sobelx = cv2.Sobel (IMG, cv2.CV_64F, 1,0, ksize =. 3) # test only horizontal direction sobely = cv2 .Sobel (IMG, cv2.CV_64F, 0,1, ksize =. 3) # test only horizontal direction sobely1 = cv2.convertScaleAbs (sobely) sobelx1 = cv2.convertScaleAbs (sobelx) soblexy = cv2.addWeighted (sobelx1,0.5, sobely1 , 0.5 , 0) Laplacian = cv2.Laplacian (IMG, cv2.CV_64F) Laplacian = cv2.convertScaleAbs (Laplacian) RES = np.hstack ((soblexy, Laplacian)) cv2.imshow ( 'erosion', res) cv2.waitKey(0)