0

I have two large grayscale images. Either PIL.Image or numpy data structure.

How do I do 1d convolution of the two images along one axis?

The best I come up with is

def conv2(im1, im2, *args):
    res = 0
    for l1, l2 in zip(im1, im2):
        res += np.convolve(l1, l2, *args)
    return res

Which works, but not extremely fast. Is there a faster way?

Please note that all the 2D convolution functions are probably not relevant since I am not interested in a 2D convolution. I've seen this question on SO before, but I didn't see a better answer than my code. So I'm bumping it again.

physicalattraction
  • 6,485
  • 10
  • 63
  • 122
Aguy
  • 7,851
  • 5
  • 31
  • 58
  • 1
    Possible duplicate of [Convolution along one axis only](http://stackoverflow.com/questions/5228718/convolution-along-one-axis-only) – Praveen Aug 06 '16 at 00:58

1 Answers1

2

FFT along one axis, multiply along one axis and inverse FFT. Should be MUCH faster according to this explanation Scipy.signal.fftconvolve should do the job.

Jacques de Hooge
  • 6,750
  • 2
  • 28
  • 45