MATLAB: Circle detection using imfindcircle

circledetectionellipseimageImage Processing Toolboxsensitivity

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.

Best Answer

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