imfindcircles doesn't work

The image looks normal with range from 0 to 4096:
[x,y] = size(AA1); % output x and y both 512
Obviously radius range is [x/4 x/2].
However, both of below:
[centers, radii, metric] = imfindcircles(AA1,[fix(x/4) fix(x/2)],'ObjectPolarity','bright')
[centers, radii, metric] = imfindcircles(AA1,[fix(x/4) fix(x/2)])
output:
centers = []
radii = []
metric = []
changed to [x/6 x/2] doesn't help.
Thank you for finding the issue!

3 comentarios

Image Analyst
Image Analyst el 29 de Jun. de 2025
Are you trying to find the mask, which would be the overall circle, or circles inside the circular area? Please indicate what circles you expect to find. Obviously the overall mask could be found by thresholding:
maskBoundary = bwboundaries(AA1 > 0);
If you want circles within that, your data is too blurry and indistinct to find with imfindcircles. You'll have to use a different method to find whatever it is you expect to find in that blurry image.
Also, size() returns [rows, columns] and it's convention to have x be horizontal - the opposite of what you have. You have x as rows (vertical) and y as columns (horizontal dimension) which is the opposite of convention though in this case since they're both 512 it doesn't make any different. Nonetheless, to be less confusing, you should choose descriptive variable names, like
[rows, columns, numberOfColorChannels] = size(grayImage);
John
John el 29 de Jun. de 2025
Even made it binary:
AAB = zeros(size(AA1));
AAB(AA1>max(AA1(:))/2) = 1;
figure;imshow(AAB,[])
it showed a great binary circle:
[centers, radii, metric] = imfindcircles(AAB,[for all ranges])
Output still is:
centers = []
radii = []
mtric = []
Image Analyst
Image Analyst el 30 de Jun. de 2025
If you have any more questions, then attach your image and code to read it in with the paperclip icon after you read this:

Iniciar sesión para comentar.

 Respuesta aceptada

Mathieu NOE
Mathieu NOE el 30 de Jun. de 2025
hello
let's try with your image
AA = imread('circle.png');
AA = rgb2gray(AA);
BW = imbinarize(AA);
[B,L,N] = bwboundaries(BW);
whos
Name Size Bytes Class Attributes AA 510x505 257550 uint8 B 1x1 17768 cell BW 510x505 257550 logical L 510x505 2060400 double N 1x1 8 double ans 1x34 68 char
figure;imshow(BW)
hold on
%Display object boundaries in red and hole boundaries in green.
N
N = 1
for k=1:length(B),
boundary = B{k};
if(k > N)
plot(boundary(:,2), boundary(:,1), 'g','LineWidth',2);
else
plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);
end
end
[m,n] =size(BW);
[centers,radii]=imfindcircles(BW,round([n/4,n/2]))
centers = 1×2
252.1513 250.1969
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
radii = 195.0940

3 comentarios

Mathieu NOE
Mathieu NOE el 4 de Jul. de 2025
hello again @John
problem solved ?
I think @John's ignoring us now - he didn't answer my comment up above either.
@Mathieu NOE did you know there is a visboundaries function?
help visboundaries
visboundaries - Plot region boundaries This MATLAB function draws boundaries of regions in the binary image BW on the current axes. Syntax visboundaries(BW) visboundaries(B) visboundaries(ax,___) visboundaries(___,Name,Value) h = visboundaries(___) Input Arguments BW - Binary image logical array B - Boundary pixel locations cell array of Q-by-2 matrices ax - Image on which to draw boundaries current axes (default) | axes object Name-Value Arguments Color - Color of boundary 'red' (default) | RGB triplet | hexadecimal color code | color name | short color name LineStyle - Style of boundary line '-' (default) | '--' | ':' | '-.' | 'none' LineWidth - Width of the line used for the boundary 2 (default) | positive number EnhanceVisibility - Augment drawn boundary with contrasting features true or 1 (default) | false or 0 Output Arguments h - Boundary lines hggroup object Examples openExample('images/ComputeBoundariesAndPlotOnImageExample') openExample('images/VisualizeSegmentationResultExample') See also bwboundaries, bwperim, bwtraceboundary, viscircles Introduced in Image Processing Toolbox in R2015a Documentation for visboundaries doc visboundaries
Mathieu NOE
Mathieu NOE el 6 de Jul. de 2025
tx for the info, I'll try to remember
as you already know , I am not truly an image expert , that's not my every day job
I'm sometimes trying to improve my basic skills in that field
don't be surprised if my answers are still a bit "basic"

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 30 de Jun. de 2025
Movida: Image Analyst el 4 de Jul. de 2025
I can't reproduce the problem you claim to have with a binarized disk. That case is pretty well-handled by imfindcircles:
n=300;
[x,y]=deal(1:n);
mask=hypot(x-mean(x),y'-mean(y))<=n/3;
[centers,radii]=imfindcircles(mask,[n/4,n/2])
centers = 1×2
150.5011 150.5011
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
radii = 99.9962
imshow(mask,[])
viscircles(centers,radii);

Categorías

Más información sobre Just for fun en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Preguntada:

el 29 de Jun. de 2025

Comentada:

el 6 de Jul. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by