Beverly Joseph | Developer :
import numpy as np
import matplotlib.pyplot as plt
image = np.array([
[0, 0, 0, 0, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 0, 0, 0, 0]
])
kernel = np.array([
[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]])
padded_image = np.pad(image, pad_width=1, mode='constant')
result = np.zeros_like(image)
for i in range(image.shape[0]):
for j in range(image.shape[1]):
result[i, j] = np.sum(i:i+3, j:j+3 * kernel)
plt.imshow(result, cmap='gray')
plt.title('Edge Detection Result')
plt.show()
2026-06-21 11:37:07