How to calculate the average radius of a boundary in Matlab ?

7 次查看(过去 30 天)
How to calculate the average radius of a boundary in Matlab ?
% Example
rng('default')
x = rand(30,1);
y = rand(30,1);
plot(x,y,'.')
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y,0.5);
hold on;
plot(x(k),y(k));

采纳的回答

Image Analyst
Image Analyst 2022-10-3
Try this:
% Example
rng('default')
x = rand(30,1);
y = rand(30,1);
plot(x,y,'r.', 'MarkerSize',30)
grid on;
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y,0.5);
hold on;
xb = x(k);
yb = y(k);
plot(xb, yb, 'b.-', 'LineWidth', 2, 'MarkerSize',30);
polyin = polyshape(xb, yb);
[xCtr, yCtr] = centroid(polyin)
plot(xCtr, yCtr, 'g+', 'LineWidth', 2, 'MarkerSize',50)
% Get the area
area = polyarea(xb, yb)
% Get the equivalent circular radius
% area = pi * r^2 so r = sqrt(area/pi)
radius = sqrt(area/pi)
% Show circle on graph.
viscircles([xCtr, yCtr], radius); % Requires Image Processing Toolbox.
axis square % So circle looks circular not elliptical.
xCtr =
0.57896610590936
yCtr =
0.522015154012119
area =
0.579388629608274
radius =
0.429447469135391

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by