# How to detect circle in this pic?

1 ビュー (過去 30 日間)
SUNGDEOK KIM 2019 年 12 月 5 日

I want detect every circle in this pic using this code. But, I detect only four.
so, How to detect every circle in this pic? what's wrong my code? clear
clc
image = edge(imgaussfilt(rgb2gray(image), 2), 'Canny');
[x y] = find(image == 1);
pindex = cat(2, y, x);
hough_matrix = zeros(1000, 1000);
rad = [55 56 64 65 51 52];
pindex = pindex + 245;
for k = 1 : 7
for p=1:size(pindex, 1)
center = pindex(p, :);
% 모든 허프 matrix에 대한 이중 for문
x = i - center(1);
y = j - center(2);
if round(sqrt(x*x + y*y)) == rad(k)
hough_matrix(j, i) = hough_matrix(j, i) + 1;
end
end
end
end
[x y] = find(hough_matrix == max(hough_matrix, [], 'all'));
center = cat(2, y, x);
center = center - 245;
if k==1
figure;imshow(image);
else
end
end

#### 0 件のコメント

サインイン to comment.

### 回答 (1 件)

Shashank Gupta 2019 年 12 月 9 日
Hi Kim,
Looks like you are trying to implement a Hough transform algorithm from the scratch. MATLAB already has the function “imfindcircles” which detect the circle in the image given a range of radius. Also this function uses the same Hough transform algorithm. But before using the function you need to do some pre-processing, I am following up your code to find the edge, now use this edged image to fill up the holes and now you can use “imfindcircle” function. This might help you.
I am also attaching a snippet of the code for the reference