title: Implement Laplacian of Gaussian Filter
body: <p>I want to implement the laplacian of gaussian filter for my image.I test this 2 method which give me completely different answer. Please tell me which I made mistake.In the first method I implement the LOG filter from it's function and in the second I use opencv functions. Here is my code for the first method:</p>
  
  <pre><code>img = np.array(Image.open('Bi00069.bmp').convert('I;16')) 
  ddepth = cv2.CV_16U
  kernel_size = 3 
  def gkern(l,sig):
  
      ax = np.linspace(-(l - 1) / 2., (l - 1) / 2., l)
      xx, yy = np.meshgrid(ax, ax)
      kernel = (-1)/(np.pi*sig**4)*(1-(xx**2+yy**2)/(2*sig**2))* 
      np.exp(-0.5 * (np.square(xx) + np.square(yy)) / np.square(sig))
  
      return kernel / np.sum(kernel)
  img1 = signal.convolve2d(img,gkern(5,5),mode='same', 
  boundary='fill', fillvalue=0)
  
  plt.imshow(G_img2,cmap='gray')
  </code></pre>
  
  <p>and my result is:
  <a href="https://i.stack.imgur.com/lfm9e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lfm9e.png" alt="enter image description here"></a></p>
  
  <p>and the second implementation is:</p>
  
  <pre><code>src = cv2.GaussianBlur(img, (3, 3), 5,cv2.BORDER_DEFAULT)
  img2 = cv2.Laplacian(src, ddepth, ksize=kernel_size)
  plt.imshow(img2,cmap='gray')
  </code></pre>
  
  <p>and here is my result:
  <a href="https://i.stack.imgur.com/2eQ9H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2eQ9H.png" alt="enter image description here"></a></p>
  
  <p>I think based on the results the second image should be correct. But I don't know what's wrong with my first implementation.Please help me.</p>