Convolution modes, pad values, and boundary conditions

Depending on what you want to do with the edge pixels, there are three arguments: modeboundary, and fillvalue, which can be passed to the SciPy convolve2d() function. Here, we'll briefly discuss the mode argument:

  • mode='full': This is the default mode, in which the output is the full discrete linear convolution of the input. 
  • mode='valid': This ignores edge pixels and only computes for those pixels with all neighbors (pixels that do not need zero-padding). The output image size is less than the input image size for all kernels (except 1 x 1). 
  • mode='same'The output image has the same size as the input image; it is centered with regards to the 'full' output.

Get Hands-On Image Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.