2017-06-05 137 views
1

我有一系列的实验图像。为了处理它,首先,我需要确定感兴趣的区域。该区域位于两个同心圆之间。这些圆圈在每个图像上可能有点不同(例如,中心可以移动一小段距离)。找到实验图像上的圆(Matlab)

为了找到这些圆圈,我将我的图像转换为二进制图像。现在看起来是这样的: enter image description here

我对最大的圆和最大的一个(见图上的注)感兴趣。有谁知道可以找到它的快速算法吗?用尽搜索似乎是一个不好的选择。我知道,在每幅图像中,这些圆圈的位置和半径只能稍稍改变。这里是一个链接到.mat文件,附图片我连接link

感谢,

+1

https://ch.mathworks.com/help/images/ref/imfindcircles.html你可能感兴趣的 –

+0

谢谢,这是非常有用的。试图实现它 –

+0

它实际上工作。唯一的是我想找到“内半径”,而不是外半径(我的圆圈有限宽度)。但我想我可以自己解决这个问题。 –

回答

2

可以实现这个任务,即使不使用内置的功能imfindcircles。我遵循以下方法。使用获取所有非零像素,找到。现在你有了所有要点,我想将它们分类到不同的圈子中,为此我将使用直方图。我可以在这里确定垃圾箱的数量(这是圈数)。一旦我把所有的点分离开来,我就会沿着一个圆点散点。用这些点,我将沿着这些点拟合一个圆。您可以检查以下代码:

load Sample.mat ; 
I = Immm ; 
[y,x] = find(I) ; 
%% Get Bounding box 
x0 = min(x) ; x1 = max(x) ; 
y0 = min(y) ; y1 = max(y) ; 
% length and breadth 
L = abs(x1-x0) ; 
B = abs(y1-y0) ; 
% center bounding box 
C = [x0+B/2 y0+L/2] ; 
%% Get distances of the points from center of bounding box 
data = repmat(C,[length(x),1])-[x,y] ; 
dist = sqrt(data(:,1).^2+data(:,2).^2); 
%% Classify the points into circles 
nbins = 4 ; % number of circles you want 
[N,edges,bin] = histcounts(dist,nbins) ; 
% plot the classified circle points for check 
figure(1) 
imshow(I) 
hold on 
for i = 1:nbins 
    plot((x(bin==i)),y(bin==i),'.','color',rand(1,3)) ; 
end 

%% Circle's radii and center 
Circ = cell(nbins,1) ; 
for i = 1:nbins 
    [xc1,yc1,R] = circfit(x(bin==i),y(bin==i)) ; 
    Circ{i} = [xc1 yc1 R] ; 
end 
figure(2) 
imshow(I) 
hold on 
th = linspace(0,2*pi) ; 
for i = 1:nbins 
    xc = Circ{i}(1)+Circ{i}(3)*cos(th) ; 
    yc = Circ{i}(2)+Circ{i}(3)*sin(th) ; 
    plot(xc,yc,'color',rand(1,3),'linewidth',3) ; 
end 

Circ是单元格,它的中心和圆的半径。你可以从这个链接下载功能circfithttp://matlab.wikia.com/wiki/FAQ#How_can_I_fit_a_circle_to_a_set_of_XY_data.3F enter image description here

+0

这是一个很好的方法,但圆心不一定完全在中心(尽管很近) –