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
조회 수: 2 (최근 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일
편집: Image Analyst
2024년 10월 31일
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!