2017-02-28 114 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.