2017-02-28 128 views

回答

2

基於衆所周知的圖像處理技術,您可以編寫自己的處理工具:

img = imread('Mlj6r.jpg'); % read the image 
imgGray = rgb2gray(img); % convert to grayscale 
sigma = 1; 
imgGray = imgaussfilt(imgGray, sigma); % filter the image (we will take derivatives, which are sensitive to noise) 
imshow(imgGray) % show the image 
[gx, gy] = gradient(double(imgGray)); % take the first derivative 
[gxx, gxy] = gradient(gx); % take the second derivatives 
[gxy, gyy] = gradient(gy); % take the second derivatives 

k = 0.04; %0.04-0.15 (see wikipedia) 
blob = (gxx.*gyy - gxy.*gxy - k*(gxx + gyy).^2); % Harris corner detector (high second derivatives in two perpendicular directions) 
blob = blob .* (gxx < 0 & gyy < 0); % select the top of the corner (i.e. positive second derivative) 

figure 
imshow(blob) % show the blobs 

blobThresshold = 1; 
circles = imregionalmax(blob) & blob > blobThresshold; % find local maxima and apply a thresshold 
figure 
imshow(imgGray) % show the original image 
hold on 
[X, Y] = find(circles); % find the position of the circles 
plot(Y, X, 'w.'); % plot the circle positions on top of the original figure 
nCircles = length(X) 

此代碼計數2710圈,這也許是一個輕微的(但不是那麼糟糕)高估。

下圖顯示了圓圈位置以白點表示的原始圖像。在對象的邊界處進行了一些錯誤的檢測。您可以嘗試對常量sigma,kblobThresshold進行一些調整以獲得更好的結果。特別是,更高的k可能是有益的。有關Harris角點檢測器的更多信息,請參見wikipedia

Original image with the circle position indicates as white dots.