检测图像中这些圆形的最快方法是什么?
半径总是在(80-100mm)之间。背景总是白色的。圆圈永远在中心。
我试过了Hough Transform但我无法真正让它发挥作用。我是新手,我觉得 Hough Transform 对此有点矫枉过正。请建议我正确的方法来做到这一点。
更新
这是应用霍夫变换后得到的结果。
我使用了提到的算法here .
以下是大算法的相关代码
% applying Hough Below
[accum, circen, cirrad] = ...
CircularHough_Grd(gR, [89 93],...
17.4, 13, 1); % this executes in 0.72 sec
% Lets see what we got
imshow(gR);
hold on;
plot(circen(:,1), circen(:,2), 'r+');
for ii = 1 : size(circen, 1)
rectangle('Position',[circen(ii,1) - cirrad(ii), circen(ii,2) - cirrad(ii), 2*cirrad(ii), 2*cirrad(ii)],...
'Curvature', [1,1], 'edgecolor', 'b', 'linewidth', 1.5);
end
hold off;
有意义的圆圈是中间的圆圈。
最佳答案
以下是我的建议:
1. 转换为灰度图像,增强“与白色的区别”
gimg = min( img, [], 3 );
2.去除白色区域的阈值
BW = im2bw( gimg, .4 );
3. 获取图像区域的面积和质心属性
st = regionprops( ~BW, 'Area', 'Centroid', 'PixelIdxList' );
4.只选择足够大的区域
sel = [st.Area] > numel(BW)*0.025; % at least 2.5% of image size
st = st(sel);
5.计算区域到图像中心的距离
cntr = .5 * [size(BW,2) size(BW,1)]; % X-Y coordinates and NOT Row/Col
d = sqrt( sum( bsxfun(@minus,vertcat( st.Centroid ), cntr ).^2, 2 ) );
6.选择离中心最近的区域
[mn idx] = min(d);
7.创建掩码
res = false(size(BW));
res( st(idx).PixelIdxList ) = true;
您还可以考虑使用其他区域属性(例如,'Eccentricity'
)来更好地拒绝非圆形区域。
关于matlab - 在 MATLAB 中检测图像内部的圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20400873/