The Sobel operator detects edges in images by computing the gradient magnitude at each pixel. It uses two 3x3 kernels to estimate horizontal and vertical derivatives, then combines them into a single edge strength value.
Given a 2D grayscale image, apply the Sobel operator with zero-padding and return the gradient magnitude at each pixel.
Input:
image = [[0, 0, 10, 10], [0, 0, 10, 10], [0, 0, 10, 10]]
Output:
A 3x4 grid where pixels near the vertical edge (columns 1-2) have high gradient values and pixels in uniform regions have lower values.
Input:
image = [[100]]
Output:
[[0.0]]
A single pixel surrounded by zero-padding has Gx and Gy that cancel due to kernel symmetry, but the padded border creates gradients at image edges for larger images.
Create a zero-padded version of the image first. Then for each output pixel (i,j), the 3x3 patch in the padded image starts at (i, j).
Gx and Gy are computed as element-wise products of the kernel and the image patch, then summed. Use math.sqrt for the final magnitude.
Sign in to take notes on this problem
Accepts: array
The Sobel operator detects edges in images by computing the gradient magnitude at each pixel. It uses two 3x3 kernels to estimate horizontal and vertical derivatives, then combines them into a single edge strength value.
Given a 2D grayscale image, apply the Sobel operator with zero-padding and return the gradient magnitude at each pixel.
Input:
image = [[0, 0, 10, 10], [0, 0, 10, 10], [0, 0, 10, 10]]
Output:
A 3x4 grid where pixels near the vertical edge (columns 1-2) have high gradient values and pixels in uniform regions have lower values.
Input:
image = [[100]]
Output:
[[0.0]]
A single pixel surrounded by zero-padding has Gx and Gy that cancel due to kernel symmetry, but the padded border creates gradients at image edges for larger images.
Create a zero-padded version of the image first. Then for each output pixel (i,j), the 3x3 patch in the padded image starts at (i, j).
Gx and Gy are computed as element-wise products of the kernel and the image patch, then summed. Use math.sqrt for the final magnitude.
Sign in to take notes on this problem
Accepts: array