title: Python image convolution with numpy slices produces strange results on some images
body: <p>I'm trying to implement a convolution in a plugin in GIMP using Numpy, and I'm getting some strange results.</p>
  
  <p>The function giving me problems is this one: (It is only operating on a grayscale image)</p>
  
  <pre><code>def convolve(self, pixels, kernel):
    bw, bh = pixels.shape
    k_w, k_h = kernel.shape
    if (k_w != k_h):
      raise ValueError("Passed kernel is not of the right shape")
  
    #expand the image
    bigger = np.lib.pad(pixels, int(k_w/2), 'reflect').astype(np.float)
  
    pixels.fill(0)
    pixels = pixels.astype(np.float)
    for x in range(k_w):
      for y in range(k_h):
        pixels += kernel[x,y]*bigger[x : bw + x,
                                     y : bh + y]
    return np.clip(pixels,0,255).astype(np.uint8)
  </code></pre>
  
  <p>Somehow, for some image sizes the output gets all messed up. Specific example can be when applying a 5x5 gaussian blur on this image:  </p>
  
  <p>Input:
  <img src="https://i.stack.imgur.com/YkRdK.jpg" alt="input">  </p>
  
  <p>Incorrect output:
  <img src="https://i.stack.imgur.com/NI7md.jpg" alt="incorrect output"></p>
  
  <p>The strangest thing about this is that for a lot of images - especially square ones - the plugin works fine. For example, if I expand the Image manually in GIMP to be a square I get a correctly blurred image: </p>
  
  <p><img src="https://i.stack.imgur.com/ZU9Op.jpg" alt="correct output"></p>
  
  <p>I've tried resizing the numpy array to be a square and then cropping it back, but that surprisingly didn't fix the issue.</p>
  
  <p>EDIT: currently running the code like this:</p>
  
  <pre><code>self.convolve(pixels,
                np.array([
                [ 1, 4, 6, 4, 1,],
                [ 4,16,24,16, 4,],
                [ 6,24,36,24, 6,],
                [ 4,16,24,16, 4,],
                [ 1, 4, 6, 4, 1,],
                ], dtype=np.float)*1/256)
  </code></pre>
  
  <p>But the same issue can be seen with any 3x3 filter, where kernels such as this work fine</p>
  
  <pre><code>[  0, 0,   0,],
  [0.5, 0, 0.5,],
  [  0, 0,   0,],
  </code></pre>
  
  <p>and kernels such as this create the strange issue:</p>
  
  <pre><code>[ 0, 0.5, 0,],
  [ 0,   0, 0,],
  [ 0, 0.5, 0,],
  </code></pre>