How to fit circles in concave parts of the polygon or binary Image ?
5 次查看(过去 30 天)
显示 更早的评论
I have written the following code, but now I'm stuck. I need to find radius of curvature, which fits best at the concave parts of the figure. Please help.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/324484/image.jpeg)
if true
% cod
% Reading the Image
clc;
close all
img = imread('black.jpg');
figure(1);
imshow(img);
title('
Original Image');
% Gray Image
imgGray = rgb2gray(img);
figure(2);
imshow(imgGray);
title('Gray Image');
% Binary Image
imgbw = imbinarize(imgGray,0.36);
figure(3);
imshow(imgbw);
imgbw= imcomplement(imgbw);
BW2 = imfill(imgbw,'holes');
title('Binary Image');
%boundary of original
boundaries1 = bwboundaries(BW2);
thisBoundary1= boundaries1{1};
xo = thisBoundary1(:,2);
yo = thisBoundary1(:,1);
% smoothening the image
windowSize = 51;
kernel = ones(windowSize) / windowSize ^ 2;
blurryImage = conv2(single(BW2), kernel, 'same');
binaryImage = blurryImage > 0.5; % Rethreshold
figure (4)
imshow(binaryImage)
title('Smoothened Image');
% boundary of smoothened image
boundaries = bwboundaries(binaryImage);
thisBoundary = boundaries{1};
xb = thisBoundary(:,2);
yb = thisBoundary(:,1);
%finding centroid of smoothened Image
measurements = regionprops(binaryImage , 'Centroid');
centroidx = measurements(1).Centroid(1);
centroidy = measurements(1).Centroid(2);
% polygon approximation
p_reduced = reducepoly(thisBoundary,0.001);
xp=p_reduced(:,2);
yp=p_reduced(:,1);
end
I want something like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/324487/image.jpeg)
4 个评论
Narges Kheradmandi
2022-11-18
Many thanks for your reply. However, I think your code gives us the fitted circle for each point on the boundary of the abject but we only need the circles which fitted to the curved part of the object(as can be seen in the image that I have uploaded. I need the radius of the green circles in the picture. Do you know how can I extract them?
Image Analyst
2022-11-18
What is the link to your new question? Have you posted it yet? You can reference this discussion in it, but let's not bug @Deepank Singh with emails about activity on his question anymore. Let's start your own discussion thread.
回答(1 个)
Image Analyst
2020-6-28
I'd get the boundary points for the shape, then use the FAQ:
to fit a circle to a sliding window of points. So you get a radius of curvature for every single boundary point for that one window size. Then I'd do it for every window size in a reasonable range. For each point for each window size, I'd compute the residuals (distance from point to fitted circle). So now you know what window size gave the best fit. And you also know the radius at that location for that window size. Conceptually pretty simple. Give it a try, since I don't have any demo code for that all ready to hand to you. Probably within an hour you could get it done.
5 个评论
Image Analyst
2022-11-16
The code gives radii all along the border. What is your definition of the "best" circle radii?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!