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

  • 1
    $\begingroup$ Please make a better title. Something like "zero-padding for edge detection" would actually describe the problem! $\endgroup$ – 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.

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.

  • 1
    $\begingroup$ Wow, I had so many typos :-). Thank you for the edit. $\endgroup$ – Royi Dec 3 '16 at 22:19
  • $\begingroup$ "(it is separable, but let's ignore that)" Well, this can be important here $\endgroup$ – Laurent Duval Jan 4 at 10:42

Zero padding IS not required, per se. However, rooting on the centered $3\times 3$ square kernel, pixels on the borders of the image lack outer neighbors, if one wants to estimate their discrete derivative/smoothing. So you have to, either:

  • use a shorter derivative estimator on image borders (which does not make assumptions regarding side effects), like Roberts cross edge detectors, or
  • extend the image properly; zero-padding (for centering, one more row or column on the right and left, and bottom or bottom, suffices) is the simplest version, but symmetric/anti-symmetric, periodic or mirror extensions can be more appropriate, or
  • use non-linear operators, that could be more robust, or
  • discard border values, which you cannot compute in any sound manner without assumptions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.