How do I detect a circle in an image?

조회 수: 21 (최근 30일)
BubbleFlow
BubbleFlow 2020년 10월 15일
답변: Pratheek Punchathody 2020년 11월 17일
I have a sequence of images (that's why the code is in a loop) which I have taken of an oscillating bubble on a needle. the images are quite noisy so I first tried to reduce the grainy spots with moderate results. I have turned the image into a binary image and I am still not able to detect the white ring which would be the bubble. Does anyone have an idea how I could detect the center and the area of the bubbles. The bubbles are not always perfectly round, so I don't know if that poses a problem in detecting them in the images.I have attached an original image.
Essentially, I have implemented two methods for detecting the circle, however the first method which is in the main loop gives out garbage and the second method which is in the second for loop just doesn't detect the ring.
for i=1:1
imname=sprintf('B00%02d.png', i);% reading the sequence of names of the images
image=imread((fullfile(path, imname)));
ima=rgb2gray(image);%grayscayling images
Kmedian = wiener2(ima,[2 2]);%adding filter
im{i}= bwareaopen(imbinarize(Kmedian),10);% binary image and removing noise
se = strel('disk',4);
im{i} = imclose(im{i},se);%connecting the existig dots
%imshow(im{i})
clear image ima
%%%%First method%%%%
[L,num] = bwlabeln(im{i},8) ; % num gives you closed region
m = regionprops(L) ; % measurements of regions, gives centers of the regions
for j = 1:num
c = m(j).Centroid ;
imshow(im{i})
hold on
plot(c(1),c(2),'*r') ;
end
end
%%%%second method%%%%
for i=1:1
imshow(im{i})
d = drawline
pos = d.Position;
diffPos = diff(pos);
diameter = hypot(diffPos(1),diffPos(2))
[centers,radii] = imfindcircles(ima,[800 950],'ObjectPolarity','bright', 'Sensitivity', 0.1)
viscircles(centers, radii,'Color','b');
end

답변 (1개)

Pratheek Punchathody
Pratheek Punchathody 2020년 11월 17일
For this specific use case, you can try out "active contour" based segmentation technique. The following documentation link has the description of the function and an example for the same : Activecontour
Hope this helps

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by