6
$\begingroup$

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?

$\endgroup$
2
  • 1
    $\begingroup$ Please make a better title. Something like "zero-padding for edge detection" would actually describe the problem! $\endgroup$ Commented Dec 1, 2016 at 8:59
  • $\begingroup$ Could you please mark my answer? $\endgroup$
    – Royi
    Commented Apr 1, 2021 at 8:16

2 Answers 2

2
$\begingroup$

Zero padding IS not required, per se. However, with a $3\times 3$ square kernel, pixels exactly on the borders of the image lack outer neighbors, if one wants to estimate their discrete derivative/smoothing. This is somehow illustrated below

border kernel

You can:

  • use a shorter derivative estimator on image borders (which does not make assumptions regarding side effects), like Roberts cross edge detectors,
  • 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. Yet, symmetric/anti-symmetric, periodic or mirror extensions can be more appropriate: half-pixel or whole pixel antisymmetric extensions respect better the continuity and smothness of border features.
  • use non-linear operators/filters, that could be more robust (median, stack, rank, mathematical morphology)
  • discard border values, which you cannot compute in any sound manner without assumptions.
$\endgroup$
1
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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