title: Simple Python Blur Convolution Kernel Function Generates Weird Image
body: <p>I was writing a custom function to apply a blur to an image using a convolution kernel. When I show the image, however, there is a weird result. In some ways is seems that the image was inverted, but I am not sure why. Here is the original image:</p>
  
  <p><a href="https://i.stack.imgur.com/JFi7M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JFi7M.png" alt="Original Image"></a></p>
  
  <p>Here is the result:</p>
  
  <p><a href="https://i.stack.imgur.com/Sryv0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Sryv0.png" alt="enter image description here"></a></p>
  
  <p>I have already tried re writing the code, changing the image, changing the blur kernel, printing and personally going through many convolutions by eye, etc.</p>
  
  <pre><code>import cv2
  import numpy as np
  import matplotlib.pyplot as plt
  
  def showImage(image):
      plt.imshow(image, cmap='gray')
      plt.show()
  
  
  def gaussianBlur(image):
      tempImage = image.copy()
      tempImage = np.pad(tempImage, 1, "constant")
  
      showImage(tempImage)
      max = 0
      i = 0
      for x in range(1, len(image)-1):
          for y in range(1, len(image[0])-1):
              roi = image[x-1:x+2, y-1:y+2]
              kernel = np.array([
                  [0.0625, 0.125, 0.0625],
                  [0.125, 0.25, 0.125],
                  [0.0625, 0.125, 0.0625]
              ])
  
              if np.matmul(roi, kernel).sum() &gt; max:
                  max = np.matmul(roi, kernel).sum()
              tempImage[x][y] = np.matmul(roi, kernel).sum()
  
              i += 1
  
              print(np.matmul(roi, kernel).sum())
              # if(i % 1000 == 0):
              #     showImage(tempImage)
  
      divAmount = max / 255
  
      for x in range(1, len(image)-1):
              for y in range(1, len(image[0])-1):
                  tempImage[x][y] = tempImage[x][y] / divAmount
      return tempImage.tolist()
  
  # Load and view the image
  image = cv2.imread("image_1_small.jpg", 0)
  showImage(image)
  
  # Apply Blur
  image = gaussianBlur(image)
  print(image)
  # image = cv2.GaussianBlur(image, (5, 5), 0)
  showImage(image)
  </code></pre>
  
  <p>The expected outcome should look like the original image only blurred.</p>