
<SYSTEM_TASK:>
Given the following text problem statement, write Python code to implement the functionality described below in problem statement
<END_TASK>
<USER_TASK:>
Problem:
write a small code snippet for edge detection for an image using python

<ASSISTANT_TASK:>
Python Code::
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import convolve2d
image = Image.open('image.jpg')
gray = np.mean(image, axis = 2)
h_x = [[1,0,-1], [2,0,-2], [1,0,-1]]
h_y = [[1,2,1], [0,0,0], [-1,-2,-1]]
g_x = convolve2d(gray, h_x)
g_y = convolve2d(gray, h_y)
a = np.square(g_x) + np.square(g_y)
G = np.sqrt(a)
plt.imshow(G, cmap='gray')

<END_TASK>
