5
$\begingroup$

The built-in function ImageConvolve takes a Padding option that "specifies what padding to use when extending beyond the original data specified." It has several useful settings, such as:

  • $\mathit{val}$: pad with a constant value $\mathit{val}$
  • "Fixed": repetitions of the elements on each boundary
  • "Periodic": cyclic repetitions of the complete array
  • "Reflected": reflections of the array in the boundary
  • "Reversed": reversals of the complete array

In principle, ListConvolve does exactly the same thing as ImageConvolve, just on a (possibly multidimensional) list rather than an image. But surprisingly, it does not accept Padding as an option. You can only provide an extra $\mathit{padlist}$ argument with which you can replicate the $\mathit{val}$ and "Periodic" settings above. Is there a straightforward way to replicate the effect of the other settings ("Fixed", "Reflected", "Reversed") in ListConvolve?

Using ImageConvolve sandwiched between Image and ImageData calls is not an option, because one might be working with symbolic or multidimensional data.

$\endgroup$
  • $\begingroup$ "surprisingly, it does not accept Padding as an option." -probably for new-ish users, I think; ListConvolve[]/ListCorrelate[] were introduced way before ArrayPad[]. If you'll compare those two with Partition[], you'll see a number of similarities. $\endgroup$ – J. M. is in limbo Oct 22 '15 at 10:21
4
$\begingroup$

You can just apply ArrayPad before performing the convolution; it supports all the desired padding forms and more. However, you'll have to adjust the third parameter of ListConvolve to get rid of the extra entries in the result.

$\endgroup$

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.