Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I don't know why this code incorrect. ( I want detect circle using canny method.)

조회 수: 1 (최근 30일)
SUNGDEOK KIM
SUNGDEOK KIM 2019년 12월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
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 = [51 55 56 64 66 69 72 75]
pindex = pindex + 245;
for k = 1:3
for p=1:size(pindex, 1)
center = pindex(p, :);
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
end
[x y] = find(hough_matrix == max(hough_matrix, [], 'all'));
center = cat(2, y, x);
center = center - 245;
figure; imshow(image);
viscircles(center, rad);
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 5일
Is this valid option here?
max(hough_matrix, [], 'all'));
SUNGDEOK KIM
SUNGDEOK KIM 2019년 12월 5일
Thank you for your reply about my question.
So, I revise my code. Can you examine my code?
(I want detect every circle in this edge image)
addtionally, i find four circle using this 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 : 6
for p=1:size(pindex, 1)
center = pindex(p, :);
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

답변 (1개)

Mahesh Taparia
Mahesh Taparia 2019년 12월 10일
Hi Kim,
You can find your answer here.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by