Fastest 2D convolution or image filter in Python

前端 未结 5 1581
遥遥无期
遥遥无期 2020-12-24 03:35

Several users have asked about the speed or memory consumption of image convolutions in numpy or scipy [1, 2, 3, 4]. From the responses and my experience using Numpy, I bel

5条回答
  •  甜味超标
    2020-12-24 04:07

    On my machine, a hand-crafted circular convolution using FFTs seems to be fasted:

    import numpy
    x = numpy.random.random((2048, 2048)).astype(numpy.float32)
    y = numpy.random.random((32, 32)).astype(numpy.float32)
    z = numpy.fft.irfft2(numpy.fft.rfft2(x) * numpy.fft.rfft2(y, x.shape))
    

    Note that this might treat the areas close to the edges differently than other ways, because it's a circular convolution.

提交回复
热议问题