# Why is zero-padding required for Sobel edge detection?

Why do we leave two rows and two columns of an image (or) padding zeros to an image for detect edges while using Sobel's operator and Prewitt's operator?

• Please make a better title. Something like "zero-padding for edge detection" would actually describe the problem! – Marcus Müller Dec 1 '16 at 8:59

The Sobel Filter is a $3 \times 3$ matrix (it is separable, but let's ignore that).

The anchor pixel is the middle one hence to evaluate the operator on pixels on the upper row the operator needs data above them.
Same goes for pixels on the last row, left-most column or right-most column.

Zero padding IS not required, per se. However, rooting on a $3\times 3$ square kernel, pixels on the borders lack neighbors for their derivative estimation. So you have to, either