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