image_interprebility/pytorch_grad_cam/sobel_cam.py

12 lines
364 B
Python
Raw Normal View History

2023-06-05 15:11:03 +08:00
import cv2
def sobel_cam(img):
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
grad_x = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=3)
grad_y = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=3)
abs_grad_x = cv2.convertScaleAbs(grad_x)
abs_grad_y = cv2.convertScaleAbs(grad_y)
grad = cv2.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0)
return grad