title: Implementing LoG blob detector in python and openCV
body: <p>I'm trying to implement an LoG blob detector according to the algortihm in wikipedia:
  <a href="https://en.wikipedia.org/wiki/Blob_detection#The_Laplacian_of_Gaussian" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Blob_detection#The_Laplacian_of_Gaussian</a></p>
  
  <p>I'm using Python and openCV and I'm using a code I got for making the filters, my code creates n level of filters, use the filters on the image and saves all the levels in an h<em>w</em>n array.
  Afterwards I look for local maxima and if I find one I mark it as the center of a blob and draw a circle around it.
  I managed to get it to work but I'm getting weird results and I'm not sure what I'm doing wrong.</p>
  
  <pre><code>myImage = cv2.imread('fishes.jpg')
  n = 15
  height, width = myImage.shape[:2]
  empty = np.empty((height+2,width+2)).astype(np.uint8)
  imgArray = np.empty((n+2,height+2,width+2)).astype(np.uint8)
  radArray = []
  imgArray[0] = empty
  imgArray[n+1] = empty
  gray_image = cv2.cvtColor(myImage, cv2.COLOR_BGR2GRAY)
  grayAllChannels = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR)
  sigma = 2
  k = 2**(0.25)
  std2 = float(sigma**2)
  for i in range(n):
      filt_size =  2*np.ceil(3*sigma)+1
      radArray.append(filt_size / 2)
      H = log_filt( filt_size, sigma)
      H *= sigma**2
      dst = cv2.filter2D(gray_image,-1,H)
      dst = cv2.copyMakeBorder(dst,1,1,1,1,cv2.BORDER_CONSTANT, value=BLACK)
      imgArray[i+1] = dst      
      sigma = sigma * k
      std2 = float(sigma**2)
  
  i = 0
  for imgIndex in range(1,n+1):
      for hIndex in range(1, height+1):
          for wIndex in range(1, width+1):
              tSlice = imgArray[imgIndex - 1:imgIndex + 2,hIndex - 1:hIndex + 2,wIndex - 1:wIndex + 2]
              tNum = imgArray[imgIndex,hIndex,wIndex]
              if (tNum &gt; imgArray[imgIndex - 1,hIndex - 1,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex - 1,hIndex - 1,wIndex] and
                  tNum &gt; imgArray[imgIndex - 1,hIndex - 1,wIndex + 1] and
                  tNum &gt; imgArray[imgIndex - 1,hIndex,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex - 1,hIndex,wIndex] and
                  tNum &gt; imgArray[imgIndex - 1,hIndex,wIndex + 1] and
                  tNum &gt; imgArray[imgIndex - 1,hIndex + 1,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex - 1,hIndex + 1,wIndex] and
                  tNum &gt; imgArray[imgIndex - 1,hIndex + 1,wIndex + 1] and
  
                  tNum &gt; imgArray[imgIndex,hIndex - 1,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex,hIndex - 1,wIndex] and
                  tNum &gt; imgArray[imgIndex,hIndex - 1,wIndex + 1] and
                  tNum &gt; imgArray[imgIndex,hIndex,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex,hIndex ,wIndex + 1] and
                  tNum &gt; imgArray[imgIndex,hIndex + 1,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex,hIndex + 1,wIndex] and
                  tNum &gt; imgArray[imgIndex,hIndex + 1,wIndex + 1] and
  
                  tNum &gt; imgArray[imgIndex + 1,hIndex - 1,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex + 1,hIndex - 1,wIndex] and
                  tNum &gt; imgArray[imgIndex + 1,hIndex - 1,wIndex + 1] and
                  tNum &gt; imgArray[imgIndex + 1,hIndex,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex + 1,hIndex,wIndex] and
                  tNum &gt; imgArray[imgIndex + 1,hIndex,wIndex + 1] and
                  tNum &gt; imgArray[imgIndex + 1,hIndex + 1,wIndex - 1] and
                  tNum &gt; imgArray[imgIndex + 1,hIndex + 1,wIndex] and
                  tNum &gt; imgArray[imgIndex + 1,hIndex + 1,wIndex + 1]):
  
                  cv2.circle(grayAllChannels,(hIndex - 1, wIndex - 1),np.int16(radArray[imgIndex - 1]),(0,30,230),2)
  </code></pre>
  
  <p>I'm getting this result:</p>
  
  <p><a href="https://i.stack.imgur.com/70h8m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/70h8m.png" alt="butterfly"></a></p>
  
  <p>Where the right result should be something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/7nCmm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7nCmm.jpg" alt="correct butterfly"></a></p>
  
  <p>Any idea what I'm doing wrong here?</p>