# detecting circle using hough tranform

3 ビュー (過去 30 日間)
Md 2022 年 9 月 18 日
コメント済み: Image Analyst 2022 年 9 月 18 日
I am trying to detect circle using hough transform using the image above. My code is
imshow(RGB);
Rmin = 60; Rmax = 100;
[center, radius] = imfindcircles(RGB, [Rmin Rmax], 'Sensitivity', 0.9)
hold on;
plot(center(:,1), center(:,2), 'yx', 'LineWidth', 2);
hold off;
It's showing error saying
"Index in position 2 exceeds array bounds.
Error in hough (line 7)
plot(center(:,1), center(:,2), 'yx', 'LineWidth', 2);"
Can I get help to fix this? Thanks in advance.

サインインしてコメントする。

### 回答 (3 件)

Simon Chan 2022 年 9 月 18 日
The range of radius is too small and the sensitivity may not be good enough.
I choose radius from 100 to 150 pixels and sensitivity 0.98 as follows:
imshow(RGB);
Rmin = 100; Rmax = 150;
[center, radius] = imfindcircles(RGB, [Rmin Rmax], 'Sensitivity', 0.98)
center = 2×2
815.0664 742.2900 434.8299 613.4308
143.3625 127.1976
hold on;
plot(center(:,1), center(:,2), 'yx', 'LineWidth', 2);
hold off;
##### 0 件のコメント表示非表示 -1 件の古いコメント

サインインしてコメントする。

Image Analyst 2022 年 9 月 18 日
center is probably empty. To correct, try changimg some of the input parameters. But why use hough/imfindcircles? For the image you showed, you can easily find the circles using the ColorThresholder (which does thresholding) or simply thresholding the green channel.
##### 2 件のコメント表示非表示 1 件の古いコメント
Image Analyst 2022 年 9 月 18 日
Oh, you didn't say it was your homework.
I've now tagged it as homework.
So what did you think of @Simon Chan's answer? It seems to work, following along the lines of your code.

サインインしてコメントする。

Matt J 2022 年 9 月 18 日

I find that imfindcircles is often hard to parameter-tune. Here's an alternative solution using this circle-fitting tool,
BW=bwareaopen(A(:,:,2)>150,500);
bd=bwboundaries(bwconvhull(BW,'objects'));
imshow(A);hold on
for i=numel(bd):-1:1
xy=fliplr(bd{i})';
fitobj=circularFit(xy);
center{i}=fitobj.center;
fitobj.showfit(LineWidth=4);
end; hold off

サインインしてコメントする。

### カテゴリ

Find more on Hough Transform in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by