我試圖根據維基百科的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算法的一部分。它應該爲您提供各種不同尺度的斑點,無需定向。 –