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

3 Ansichten (letzte 30 Tage)
Sim
Sim am 3 Okt. 2022
Kommentiert: Sim am 3 Okt. 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));

Akzeptierte Antwort

Image Analyst
Image Analyst am 3 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by