计算图像中圆心的坐标

HSN*_*HSN 5 algorithm matlab image

在此输入图像描述

说我有这个图像,我想得到每个圆的中心(X,Y).

在MatLab中是否有算法这样做?

Gun*_*uyf 5

一次调用regionprops就可以了:

img = imread('KxJEJ.jpg');                      % read the image
imgbw = ~im2bw(img,graythresh(img));            % convert to grayscale

stats  = regionprops(bwlabel(imgbw), 'centroid','area'); % call regionprops to find centroid and area of all connected objects
area = [stats.Area];                            % extract area
centre = cat(1,stats.Centroid);                 % extract centroids

centre = centre(area>10,:);                     % filter out dust specks in the image
Run Code Online (Sandbox Code Playgroud)

现在centre包含一个Nx2数组:第一列是x位置,第二列是中心的y位置:

centre =

   289.82       451.73
   661.41       461.21
   1000.8       478.01
   1346.7       482.98
Run Code Online (Sandbox Code Playgroud)


Ser*_*erg 2

这是使用人工圆互相关作为滤波器的结果。结果是从左上角开始[行,列]:

>> disp(centers)
         483        1347
         460         662
         478        1001
         451         290
Run Code Online (Sandbox Code Playgroud)

没有详细的评论,需要的请询问。

im = rgb2gray(im2double(imread('D:/temp/circles.jpg')));
r = 117; % define radius of circles
thres_factor = 0.9; % see usage
%%
[x, y] = meshgrid(-r : r);
f = sqrt(x .^ 2 + y .^ 2) >= r;
%%
im = im - mean(im(:));
im = im / std(im(:));
f = f - mean(f(:));
f = f / std(f(:)) / numel(f);
imf_orig = imfilter(im, f, 'replicate');
%% search local maximas
imf = imf_orig;
[n_idx, m_idx] = meshgrid(1 : size(imf, 2), 1 : size(imf, 1));
threshold = thres_factor * max(imf(:));
centers = []; % this is the result
while true
    if max(imf(:)) < threshold
        break;
    end
    [m, n] = find(imf == max(imf(:)), 1, 'first');
    centers = cat(1, centers, [m, n]);
    % now set this area to NaN to skip it in the next iteration
    idx_nan = sqrt((n_idx - n) .^ 2 + (m_idx - m) .^ 2) <= r;
    imf(idx_nan) = nan;
end
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述