matlab - 在 MATLAB 中从灰度图像进行圆检测

标签 matlab image-processing geometry

我有下面显示的图像。我的目标是检测第二张图片中显示的圆圈。我使用了 [centers,radii] = imfindcircles(IM,[100 300]); 但它什么也没找到。

还有其他检测圆的方法吗?我该怎么做?

原图: enter image description here

圆圈:我用颜料画的。 enter image description here

最佳答案

这是 imfindcircles 的替代解决方案。基本上对图像进行阈值处理,用磁盘结构元素对其进行扩展,然后在找到边缘后,应用 Hough 变换以使用文件交换中提供的 circle_hough 算法检测圆 here .

代码如下:

clear
clc
close all

A = imread('CircleIm.jpg');

%// Some pre-processing. Treshold image and dilate it.
B = im2bw(A,.85);

se = strel('disk',2);

C = imdilate(B,se);

D = bwareaopen(C,10000);

%// Here imfill is not necessary but you might find it useful in other situations.
E = imfill(D,'holes');

%// Detect edges
F = edge(E);

%// circle_hough from the File Exchange.

%// This code is based on Andrey's answer here:
%https://dsp.stackexchange.com/questions/5930/find-circle-in-noisy-data.

%// Generate range of radii.
 radii = 200:10:250;

h = circle_hough(F, radii,'same');
[~,maxIndex] = max(h(:));
[i,j,k] = ind2sub(size(h), maxIndex);
radius = radii(k);
center.x = j;
center.y = i;

%// Generate circle to overlay
N = 200;

theta=linspace(0,2*pi,N);
rho=ones(1,N)*radius;

%Cartesian coordinates
[X,Y] = pol2cart(theta,rho); 

figure;

subplot(2,2,1)
imshow(B);
title('Thresholded image  (B)','FontSize',16)

subplot(2,2,2)
imshow(E);
title('Filled image (E)','FontSize',16)

subplot(2,2,3)
imshow(F);hold on

plot(center.x-X,center.y-Y,'r-','linewidth',2);

title('Edge image + circle (F)','FontSize',16)

subplot(2,2,4)
imshow(A);hold on
plot(center.x-X,center.y-Y,'r-','linewidth',2);
title('Original image + circle (A)','FontSize',16)

给出以下内容:

enter image description here

您可以尝试传递给 threshold 或 dilate 的参数,看看它如何影响结果。

希望对您有所帮助!

关于matlab - 在 MATLAB 中从灰度图像进行圆检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27171527/

相关文章:

matlab - 我们如何在 matlab 中处理大矩阵(大于 10000x10000)

java - 从 MATLAB 执行时如何为 JAVA 程序分配更多内存?

python - 将具有透明背景的图像与普通图像(非透明背景)混合后如何调整 alpha 值?

python - Python OpenCV中的侵 eclipse 和膨胀返回白色

image - Matlab:找到轮廓并拉直近乎矩形的图像

java - 检查投影到线段上的点是否不在线段之外

algorithm - 凸包由最大组成。 n 点

matlab - 不断收到无效的表达错误

matlab - 如何在 MATLAB 中使用矩形放样以创建灵活的 3D 封闭管道?

math - 球面坐标到平面的距离