The Sobel operator detects image edges by estimating horizontal and vertical intensity changes. Given a two-dimensional grayscale image, compute the gradient magnitude at every pixel.
Pad the image with one row or column of zeros on every side. Use the following horizontal kernel:
Kx=−1−2−1000121Use the following vertical kernel:
Ky=−101−202−101For each image position with coordinates (i, j), center both kernels on that position and compute:
Gx(i,j)=a=0∑2b=0∑2Kx(a,b)P(i+a,j+b) Gy(i,j)=a=0∑2b=0∑2Ky(a,b)P(i+a,j+b)Combine the two directional responses:
G(i,j)=Gx(i,j)2+Gy(i,j)2Here, P is the zero-padded image, i and j identify an output pixel, and a and b identify a kernel position.
Return G as a two-dimensional list of floats with the same height and width as the input image.
Input: image = [[0, 0, 10, 10], [0, 0, 10, 10], [0, 0, 10, 10]]
Output: [[0.0, 31.622776601683793, 42.42640687119285, 42.42640687119285], [0.0, 40.0, 40.0, 40.0], [0.0, 31.622776601683793, 42.42640687119285, 42.42640687119285]]
Explanation: The vertical intensity transition produces large horizontal Sobel responses.
Input: image = [[100]]
Output: [[0.0]]
Copy the image into the center of a grid with a one-pixel zero border.
Accumulate horizontal and vertical kernel responses before taking their Euclidean magnitude.
Sign in to take notes on this problem
Accepts: array
The Sobel operator detects image edges by estimating horizontal and vertical intensity changes. Given a two-dimensional grayscale image, compute the gradient magnitude at every pixel.
Pad the image with one row or column of zeros on every side. Use the following horizontal kernel:
Kx=−1−2−1000121Use the following vertical kernel:
Ky=−101−202−101For each image position with coordinates (i, j), center both kernels on that position and compute:
Gx(i,j)=a=0∑2b=0∑2Kx(a,b)P(i+a,j+b) Gy(i,j)=a=0∑2b=0∑2Ky(a,b)P(i+a,j+b)Combine the two directional responses:
G(i,j)=Gx(i,j)2+Gy(i,j)2Here, P is the zero-padded image, i and j identify an output pixel, and a and b identify a kernel position.
Return G as a two-dimensional list of floats with the same height and width as the input image.
Input: image = [[0, 0, 10, 10], [0, 0, 10, 10], [0, 0, 10, 10]]
Output: [[0.0, 31.622776601683793, 42.42640687119285, 42.42640687119285], [0.0, 40.0, 40.0, 40.0], [0.0, 31.622776601683793, 42.42640687119285, 42.42640687119285]]
Explanation: The vertical intensity transition produces large horizontal Sobel responses.
Input: image = [[100]]
Output: [[0.0]]
Copy the image into the center of a grid with a one-pixel zero border.
Accumulate horizontal and vertical kernel responses before taking their Euclidean magnitude.
Sign in to take notes on this problem
Accepts: array