matlab - 在 MATLAB 中检测图像内部的圆形

标签 matlab image-processing shapes

检测图像中这些圆形的最快方法是什么?

Red Circle to be detected

半径总是在(80-100mm)之间。背景总是白色的。圆圈永远在中心。

我试过了Hough Transform但我无法真正让它发挥作用。我是新手,我觉得 Hough Transform 对此有点矫枉过正。请建议我正确的方法来做到这一点。 enter image description here


更新

这是应用霍夫变换后得到的结果。

我使用了提到的算法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;

enter image description here

有意义的圆圈是中间的圆圈。

最佳答案

以下是我的建议:
1. 转换为灰度图像,增强“与白色的区别”

gimg = min( img, [], 3 );

enter image description here
2.去除白色区域的阈值

BW = im2bw( gimg, .4 ); 

enter image description here
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;

enter image description here

您还可以考虑使用其他区域属性(例如,'Eccentricity')来更好地拒绝非圆形区域。

关于matlab - 在 MATLAB 中检测图像内部的圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20400873/

相关文章:

python - 使用 Numpy 计算亲和矩阵

c++ - opencv brg 颜色直方图不起作用

C++ - 停止无限循环 - 追踪轮廓

android - 如何在xml中设置形状的背景?

python - 为什么我的 Pandas 数据框选择的形状是错误的

matlab - 在 MATLAB 中不重新缩放的情况下在轴外添加图例

python - 在 Python 中将一个数组分配为另一个数组的组成部分

wpf - 使用WPF圆窗播放电影

matlab - 矩阵直和

unit-testing - Matlab xUnit 框架测试套件设置