Trying to figure out the roughness of a circle imfindcircles pol2cart, but not getting the results I expect
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone
So this is maybe a simple question, but for some reason I'm not getting the answer I expect. I start of with an image that has circles in it. In my case, the circles are not perfect circles, and I want to get an idea of how rough te circles are. To do this, I have a 2 step process. Find the center of the circles by using imfindcircles. After I've figured out my centers, I then use pol2cart to figure out where the drop-off point in my circle for that particular theta is. Now, I say the circles are rough, but they are still supposed to be very circular, so when I run the following code, I expected to see a regular p[attern that only changes very mildy. However, this is not the case.
d = dir(directory(i) + "\\*.png");
d = arrayfun(@(x) x.folder + "\\" + x.name, d);
I = (imread(d(1)));
[centers,radii,metric] = imfindcircles(I,[400 700],'Sensitivity',0.99);
%%figure out bottom to top
y = centers (:,2);
[B,k] = sort(y);
centers = centers(k,:);
radii = radii(k);
subplot(1,3,i)
imshow(I);
viscircles(centers,radii);
I = double(I);
figure
%%for all centers, go through 360 degrees
for j = 1:size(centers,1)
xo = centers(j,1);
yo = centers(j,2);
xo = round(xo);
yo = round(yo);
for theta = 1:360
rho = 0:round(1.2*radii(j));
for r = 1:length(rho)
try
[x,y] = pol2cart(theta,rho(r));
x = round(x);
y = round(y);
line(r) = I(xo + x, yo + y);
catch
line(r) = 0;
end
end
line = medfilt1(line);
hold on
plot(line)
end
end
I've plotted the first few thetas to show what I mean about the results not being what I expected.
0 个评论
采纳的回答
Image Analyst
2023-2-9
What I'd do is to use bwboundaries to get the coordinates of the boundaries and then computer the MAD or RMS of the actual boundary from the fitted circle. Let me know if you can't figure it out and need code.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
3 个评论
Image Analyst
2023-2-9
It doesn't matter where the boundary starts. For a single boundary, try something like
boundaries = bwboundaries(mask);
b = boundaries{1}; % Get the first boundary out of the cell into a matrix.
x = b(:, 1);
y = b(:, 2);
meanAbsDev = mean(sqrt((x - xCenter).^2 + (y - yCenter).^2));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!