Detect edges in a grayscale image using simple gradient-based edge detection:
Gx[i][j]=2Input[i][j+1]−Input[i][j−1]
Gy[i][j]=2Input[i+1][j]−Input[i−1][j]
Output[i][j]=Gx[i][j]2+Gy[i][j]2
The result is normalized to the range [0, 255].
This algorithm computes horizontal and vertical gradients, then combines them to find edge strength at each pixel.
Input:
- Grayscale image of size height×width
Output:
- Edge detected image of size height×width
Notes:
- The input tensor is a single-channel grayscale image
- Only compute gradients for interior pixels (ignore 1-pixel border)
- Border pixels remain zero in the output