假设我有这个图像,我想得到每个圆的中心(x,y)。
在Matlab中有这样的算法吗?是吗?

最佳答案

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

>> disp(centers)
         483        1347
         460         662
         478        1001
         451         290

没有详细的评论,请按要求询问。
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

08-19 16:29