How to detect circle in this pic?
1 回表示 (過去 30 日間)
古いコメントを表示
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 = imread('example5.PNG');
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문
for i = center(1)-rad(k):center(1)+rad(k)
x = i - center(1);
for j = center(2)-rad(k):center(2)+rad(k)
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
viscircles(center, rad(k));
end
end
0 件のコメント
回答 (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
image = imread('image.png');
image = edge(imgaussfilt(rgb2gray(image), 2), 'Canny');
img = imfill(image,'holes');
imshow(img);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で 객체 분석 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!