1
$\begingroup$

I am puzzled by what actually happens when you process border cases when applying an image filter. For instance if I apply a 3x3 Gaussian kernel to the top left pixel[0][0], the remaining pixels that are unable to convolute will go to the right and bottom of the image. But do you multiply them again or u replace the original pixels?

[1, 2, 1,
 2, 4, 2, 
 1, 2, 1] // 4,2 & 2, 1 will convolute with the pixels in image but how about row 1,2,1 and col 1,2,1 ?
$\endgroup$
0
$\begingroup$

There are three main attitudes when dealing with borders of images and filter kernels.

  1. The simplest is to only process the pixels that have enough neighboring pixels. As a result, some pixels on the sides are left unprocessed, and the filtered image can be cropped.
    1. The shape of the filter can be adapted (notably in size) to fit the neighborhood of of the running pixel.
    2. The image is extended to the appropriate size. There are many extension methods, from filling with zeroes or constant values to clever extrapolation.

Traditionally, symmetric or antisymmetric extensions are used in many cases, since this is quite consistent with the symmetries or antisymmetries of filter kernels themselves, and this can be performed efficiently. Wraparound is also performed, and sometimes implicit when using FFT filtering or discrete wavelet restoration. Due to discontinuities (the far ends of the image can be quite different), a preprocessing is advised (windowing, smoothing, background removal).

$\endgroup$
4
  • 1
    $\begingroup$ Thanks for the reply! What if i choose to wrap the filter around an image? Do the indices of the filter that don't fit the corner of the image get 'multiplied' when they are wrapped to the right/ left / top/ bottom of the image? or it is a direct replacement? $\endgroup$ – HC Tang Jun 8 '20 at 9:55
  • $\begingroup$ Yes, this is an instance of periodic extension. The top-left corner is "filled" by bottom right pixels. Indeed, this is performed implicitly sometimes when using FFTs. However, this might lead to artifacts, due to a discontinuity between far-away pixels. A preprocessing might be needed: windowing, background removal $\endgroup$ – Laurent Duval Jun 8 '20 at 10:20
  • $\begingroup$ Thanks I understand now :) $\endgroup$ – HC Tang Jun 8 '20 at 10:35
  • $\begingroup$ Thank you for the validation. I have updated the answer to reflect the comments $\endgroup$ – Laurent Duval Jun 8 '20 at 10:38

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.