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

3 visualizaciones (últimos 30 días)
Sim
Sim el 3 de Oct. de 2022
Comentada: Sim el 3 de Oct. de 2022
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));

Respuesta aceptada

Image Analyst
Image Analyst el 3 de Oct. de 2022
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

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by