Image smoothing in Python

前端 未结 3 1035
慢半拍i
慢半拍i 2020-12-28 08:09

I wanted to try to write a simple function to smooth an inputted image. I was trying to do this using the Image and numpy libraries. I was thinking that using a convolution

3条回答
  •  天涯浪人
    2020-12-28 08:59

    If you don't want to use scipy, you have three options:

    1) you can use the convolution theorem combined with Fourier transforms since numpy has a 2D FFT.

    2) you can use a separable kernel and then you can do two 1D convolutions on flattened arrays, one in the x-direction and the other in the y-direction (ravel the transpose), and this will give the same result as the 2D convolution.

    3) if you have a small kernel, say, 3x3, it's easy enough just to write out the convolution as multiplications and sums. This sounds like a hassle but it's not so bad.

    If you do want to use scipy, you can use ngimage, as tcaswell suggests. scipy also has convolve2d.

提交回复
热议问题