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?
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.
This is usually solved by padding the image (I actually use "Replication" instead of Zero Padding).
Another option is to set the output to be smaller image by not evaluating the extreme rows or columns.
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
- use a shorter derivative estimator on borders (which does not make assumptions regarding side effects) use: zeropzdddigs, symmetric/antisymmetric, periodic or mirror extensions