Circle detection using imfindcircle

조회 수: 5 (최근 30일)
Adem Kikaj
Adem Kikaj 2017년 1월 16일
답변: Laura Achola 2022년 9월 19일
Hi to all, I'am trying to detect circle in this image using this:
[centerPoints, radius] = imfindcircles(newImage ,[2 30],'ObjectPolarity','dark','Sensitivity',0.98);
As you can see I'am in a very high Sensitivity looking for circles in this image but it won't find my circle in Wheat Color just the one in back with black line.
Also I have tried with some color enhancement but it won't work.

채택된 답변

John BG
John BG 2017년 1월 17일
Hello Kika
I found a way to spot the inner circle:
1.
capture
A=imread('im1.jpg');
figure(1);h1=imshow(A);
2.
running the cursor around the picture one realises the circle you are after is slightly 'yellow'.
a saturated yellow would be: Yellow = Red + Green [1 1 0]
but this is a rather mild yellow, meaning that the red and green layers of the image are only between 15 and 35 points above the blue layer across the points of interest.
Let's catch these slightly yellow pixels:
A13=A(:,:,1)-A(:,:,3);A23=A(:,:,2)-A(:,:,3);
[x13,y13]=find(A13>30);
% [x23,y23]=find(A23>20);
% x=intersect(x13,x23);y=intersect(y13,y23);
figure(2);imshow(A)
hold all
figure(2);h1=plot(y13,x13,'y*')
3.
one could go now for the function imfindcircles that automates fitting circles, but instead of start guessing what parameters of this function would be the right ones, I chose to do a it manually, a bit a of exercise cannot harm, can it?
A2=A;
A2(x13,y13,1)=255;A2(x13,y13,2)=255;A2(x13,y13,2)=0;
figure(3);h1=imshow(A2);
4.
the square is fairly centred, so all left is to plot a circle
r=floor(mean([abs(min(x13)-max(x13)) abs(min(y13)-max(y13))])/2);
xc=floor(.5*abs(min(x13)+max(x13)));
yc=floor(.5*abs(min(y13)+max(y13)));
figure(1);plot(yc,xc,'g*')
da=1;a=[0:da:360];
px=r*cosd(a)+yc;py=r*sind(a)+xc;
figure(1);plot(px,py,'ro')
dear Kika
either with imfindcircles or shanks mare, the result is the same, you catch the inner circle.
if you find these lines useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, if you find this answer of any help please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG
.
additional comment:
1.
it turns out that the mildly yellow points can only be spotted with the variance of the RGB layers
figure(4);varA=surf(var(double(A),0,3));
.
use the Rotate 3D function in the figure window to move the point of view and appreciate the target circle right on the hill that generates the variance for this picture
.
I tried different variance thresholds
vA=varA.CData;
m=255/max(max(vA));
figure(5);imshow(m*vA);
% try var threshold at 500
[x500,y500]=find(vA>500);
hold all;
figure(1);plot(x500,y500,'r*')
% try var threshold at 400
[x400,y400]=find(vA>400);
hold all;
figure(6);plot(x400,y400,'b*')
but the above lines give a better result
  댓글 수: 3
John BG
John BG 2018년 4월 8일
Sure, please post it on another question, ok?
Let me the link to the new question, either by email or make a note here.
John BG
John BG 2018년 4월 8일
I have almost completed the solution for the tree rings counting.
If you post a new question with the tree trunk cross section and let me know the link I will post my answer as soon as you let me know.
Regards
John BG

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2017년 1월 16일
You already asked this and John and I answered and you accepted John's answer. Did it not work? Or not work for this particular color?
How many circles do you want from the image? I can see 1, 2, or 3 depending on how you define a circle. The gray ring consists of two circles, an inner one and an outer one, though they're not complete.
You haven't given the context for what you're doing. Why do you need to find circles? For example if you're looking at a 96 well plate, then simply put your plate into a jig/bracket, snap a picture of it and have a template to look in the same locations all the time. Why bother finding them if they don't move around? Just use a template/mask. For example you could take a blank shot, determine colors in the circles of the template, then take a sample image with stuff in there and compute Delta E to see how much it changed.
  댓글 수: 6
Jan
Jan 2017년 1월 17일
@John BG: A figure or axes handle would not be useful, because both can contain multiple images. Therefore an image handle could be an option instead of providing the image data directly.
I do not see the reason for your "strongly recommended not to reveal work details" comment. What is the connection to this thread?
Image Analyst
Image Analyst 2017년 1월 17일
Now that we know the larger context of him trying to use computer vision to determine disc placement on a Nine Men's Morris playing board, I don't know how knowing the centroid of a playing piece is relevant. Like I've said before, just use a template and determine presence or absence of a playing piece. For example if you wanted to determine occupancy of stadium seats, would you try to determine the hair color and sex of the person occupying a seat? No, it doesn't matter - all that matters is that a seat is occupied. If you had a parking vacancy program and were looking at parking spaces, do you care if the space holds a Ford or a Honda? No, it doesn't matter so don't spend time trying to figure it out. All that matters is if a space is taken or not.

댓글을 달려면 로그인하십시오.


Laura Achola
Laura Achola 2022년 9월 19일
Try [centerPoints, radius] = imfindcircles(newImage ,[2 30],'ObjectPolarity','bright','Sensitivity',0.98);
I think the issue is that you are using the foreground as dark instead of bright. You won't need the high sensitivity in that case.

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by