The slices may not be perpendicular to the main axis of the vase, which means the radii could be a bit elliptical...
Finding the Center of Broken Vase Slices
37 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I have some slices from a broken vase and I'm trying to determine the center of each slice. Both the outer and inner edges of the slices should ideally share the same center. Can anyone suggest how I might go about finding this center for each piece?
Thank you!
2 个评论
回答(2 个)
Image Analyst
2024-10-31,14:50
编辑:Image Analyst
2024-10-31,18:03
What I'd do is to call bwboundaries on the binary image to get the coordinates of the perimeter. Do it on the original binary image if you can so you get only one boundary, otherwise use the no holes option in bwboundary so you get only the outer boundary.
Then call ginput(2) to get the user to click on two vertex points. Use sqrt() and min() to find the boundary points with the closest distance to where they clicked. Then extract the boundary between those points. Then use the attached function to fit those coordinates to an ellipse using the FAQ
or fit to a circle using the attached function.
function [a, b, h, k, theta] = fitEllipse(x, y)
% Fit an ellipse to the given (x, y) coordinates
% Returns the parameters: semi-major axis (a), semi-minor axis (b),
% center (h, k), and rotation angle (theta)
% Prepare the data
D = [x.^2, x.*y, y.^2, x, y, ones(size(x))];
S = D' * D; % Scatter matrix
[~, ~, V] = svd(S); % Singular value decomposition
a = V(:, end); % Last column of V gives the ellipse parameters
% Extract parameters
h = -a(4) / (2 * a(1));
k = -a(5) / (2 * a(3));
theta = 0.5 * atan2(a(2), a(1) - a(3));
% Calculate semi-major and semi-minor axes
% Using the formula for ellipse parameters
num = a(1) * a(3) - (a(2)^2) / 4;
a = sqrt(2 * (a(1) * h^2 + a(3) * k^2 + a(6) - a(1) * a(3) / num));
b = sqrt(2 * (a(1) * h^2 + a(3) * k^2 + a(6) - a(1) * a(3) / num));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Scene Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!