Tensara Logo

tensara

All Problems

Edge Detection

EASY

Detect edges in a grayscale image using simple gradient-based edge detection:

Gx[i][j]=Input[i][j+1]Input[i][j1]2G_x[i][j] = \frac{\text{Input}[i][j+1] - \text{Input}[i][j-1]}{2} Gy[i][j]=Input[i+1][j]Input[i1][j]2G_y[i][j] = \frac{\text{Input}[i+1][j] - \text{Input}[i-1][j]}{2} Output[i][j]=Gx[i][j]2+Gy[i][j]2\text{Output}[i][j] = \sqrt{G_x[i][j]^2 + G_y[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\text{height} \times \text{width}

Output:

  • Edge detected image of size height×width\text{height} \times \text{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
Console

Sample Run Results

Hit "Run" to test your code with sample inputs

Loading...

Loading editor...

CUDA C++ environment

Desktop Required for Code Submission

For the best coding experience, please switch to a desktop device to write and submit your solution.