我试图根据维基百科的algortihm实现一个日志BLOB探测器执行日志斑点检测: https://en.wikipedia.org/wiki/Blob_detection#The_Laplacian_of_Gaussian在python和OpenCV
我使用Python和OpenCV和我使用的是我得到了一个代码为了制作滤镜,我的代码创建了n级滤镜,使用图像上的滤镜并将所有级别保存在一个阵列中。 然后我寻找当地的最大值,如果我找到一个,我将它标记为一个斑点的中心并围绕它画一个圆。 我设法让它工作,但我得到奇怪的结果,我不知道我做错了什么。
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 > imgArray[imgIndex - 1,hIndex - 1,wIndex - 1] and
tNum > imgArray[imgIndex - 1,hIndex - 1,wIndex] and
tNum > imgArray[imgIndex - 1,hIndex - 1,wIndex + 1] and
tNum > imgArray[imgIndex - 1,hIndex,wIndex - 1] and
tNum > imgArray[imgIndex - 1,hIndex,wIndex] and
tNum > imgArray[imgIndex - 1,hIndex,wIndex + 1] and
tNum > imgArray[imgIndex - 1,hIndex + 1,wIndex - 1] and
tNum > imgArray[imgIndex - 1,hIndex + 1,wIndex] and
tNum > imgArray[imgIndex - 1,hIndex + 1,wIndex + 1] and
tNum > imgArray[imgIndex,hIndex - 1,wIndex - 1] and
tNum > imgArray[imgIndex,hIndex - 1,wIndex] and
tNum > imgArray[imgIndex,hIndex - 1,wIndex + 1] and
tNum > imgArray[imgIndex,hIndex,wIndex - 1] and
tNum > imgArray[imgIndex,hIndex ,wIndex + 1] and
tNum > imgArray[imgIndex,hIndex + 1,wIndex - 1] and
tNum > imgArray[imgIndex,hIndex + 1,wIndex] and
tNum > imgArray[imgIndex,hIndex + 1,wIndex + 1] and
tNum > imgArray[imgIndex + 1,hIndex - 1,wIndex - 1] and
tNum > imgArray[imgIndex + 1,hIndex - 1,wIndex] and
tNum > imgArray[imgIndex + 1,hIndex - 1,wIndex + 1] and
tNum > imgArray[imgIndex + 1,hIndex,wIndex - 1] and
tNum > imgArray[imgIndex + 1,hIndex,wIndex] and
tNum > imgArray[imgIndex + 1,hIndex,wIndex + 1] and
tNum > imgArray[imgIndex + 1,hIndex + 1,wIndex - 1] and
tNum > imgArray[imgIndex + 1,hIndex + 1,wIndex] and
tNum > imgArray[imgIndex + 1,hIndex + 1,wIndex + 1]):
cv2.circle(grayAllChannels,(hIndex - 1, wIndex - 1),np.int16(radArray[imgIndex - 1]),(0,30,230),2)
我得到这个结果:
当正确的结果应该是这样的:
任何想法,我做错了这里?
正确的结果应该是这样的:https://youtu.be/L77m5xuDSKw?t=23m10s - 据我所知,LoG blob检测器只是SIFT算法的一部分。它应该为您提供各种不同尺度的斑点,无需定向。 –