计算用于一个圆的中心的坐标中的图像 [英] Calculating the coordinates for the center of a circle in an image

查看:355
本文介绍了计算用于一个圆的中心的坐标中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这个形象,我想在(X,Y),每个圆圈的中心。

Say I have this image and I want to get the center of each circle in (X , Y).

有一个算法,这样做在MATLAB ??

Is there an algorithm to do so in MatLab??

推荐答案

下面是一个使用互相关人工圈作为过滤器的结果。 其结果是[行,列]从左上角:

Here is a result using cross-correlation with artificial circle as a filter. The result is [row, column] from upper left corner:

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

目前还没有详细的意见,请向它需要的。

There is no detailed comments, please ask it required.

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

这篇关于计算用于一个圆的中心的坐标中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆