[SciPy-User] Vectorised convolution

Anne Archibald aarchiba at physics.mcgill.ca
Tue Aug 2 02:56:10 EDT 2011


The blunt-instrument approach is to pad your image with zeros then
flatten it. If you're careful about memory layouts this can even be
done with a view. Either way you get a single long one-dimensional
array you can apply unvectorized 1D convolutions to. You can then
reshape the output back to two dimensions, clipping out the padding as
appropriate in the process. The big drawback is that you have to pad
the whole image at once, which could be a memory hog if your kernel is
large.

Anne

On 2 August 2011 02:35, Jason Heeris <jason.heeris at gmail.com> wrote:
> On 2 August 2011 10:57, Warren Weckesser <warren.weckesser at enthought.com>
> wrote:
>>
>> I show one way to do this in the following SciPy cookbook entry:
>
> Interesting — I just tried that approach and found that it was actually
> slower than the looped version, which seems weird.
> But the convolve1d version works great (less than a tenth of the time as my
> loop) and the lfilter version is almost as good.
> Thanks,
> Jason
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>



More information about the SciPy-User mailing list