import cv2
import matplotlib.pyplot as plt

img=cv2.imread('photo_2.jpeg',0)

sobel_x=cv2.Sobel(img,cv2.CV_64F,1,0,ksize=3)
sobel_y=cv2.Sobel(img,cv2.CV_64F,0,1,ksize=3)

sobel_x=cv2.convertScaleAbs(sobel_x)
sobel_y=cv2.convertScaleAbs(sobel_y)

sobel=cv2.addWeighted(sobel_x,0.5,sobel_y,0.5,0)

plt.figure(figsize=(10,8))
plt.subplot(2,2,1)
plt.title("Original Image")
plt.imshow(img,cmap='gray')
plt.axis('off')
plt.subplot(2,2,2)
plt.title("Sobel X (Vertical Edges)")
plt.imshow(sobel_x,cmap='gray')
plt.axis('off')
plt.subplot(2,2,3)
plt.title("Sobel Y (Horizontal Edges)")
plt.imshow(sobel_y,cmap='gray')
plt.axis('off')
plt.subplot(2,2,4)
plt.title("Sobel Edge Image")
plt.imshow(sobel,cmap='gray')
plt.axis('off')
plt.tight_layout()
plt.show()