Move/delete/create some coordinates in order to make the curve more or less uniform

1 次查看(过去 30 天)
Hello! As written in the title I am trying to figure out if there is a way to move/delete/create some coordinates in order to make the curve more or less uniform.
Below is an example (whose coordinates can be found in the attached .txt. text file).
I am trying to make the black curve more or less uniform with the coordinates marked by dots in red.

回答(1 个)

Image Analyst
Image Analyst 2022-12-13
编辑:Image Analyst 2022-12-13
The attached file is a .mat file, not a txt file. The attached data is not sorted. Is there anyway you could sort it clockwise? I got this but it's not good because your data is not sorted. I wanted to see if you had sorted data before I tried to sort it better.
data = load('coordinate_A.mat')
data = struct with fields:
out_both: [582×2 double]
x = data.out_both(:, 1);
y = data.out_both(:, 2);
% plot(x, y, 'c.', 'MarkerSize', 8)
hold on;
grid on;
axis equal
% The data is not sorted so we can't smooth it yet.
% Need to sort it clockwise.
% First need to find centroid
% Get left shape
leftIndexes = x < 250;
xLeft = x(leftIndexes);
yLeft = y(leftIndexes);
plot(xLeft, yLeft, 'b.');
hold on;
% Find centroid.
p = polyshape(xLeft, yLeft);
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
[xCentroid, yCentroid] = centroid(p)
xCentroid = 141.9855
yCentroid = 229.7115
plot(xCentroid, yCentroid, 'r+', 'MarkerSize', 40, 'LineWidth',2);
% Get angles
angles = atan2d(yLeft-yCentroid, xLeft-xCentroid);
% Sort
[sortedAngles, sortOrder] = sort(angles, 'ascend');
% Sort x and y the same way.
xLeft = xLeft(sortOrder);
yLeft = yLeft(sortOrder);
% Smooth both
windowWidth = 5;
xSmooth = movmean(xLeft, windowWidth);
ySmooth = movmean(yLeft, windowWidth);
plot(xSmooth, ySmooth, 'r-', 'LineWidth',2)
  9 个评论
Image Analyst
Image Analyst 2022-12-15
Since your data are integers, you could write them into an image and then use bwboundaries to get them in a sorted manner, then use movmean or sgloayfilt to smooth them. Try that.
Alberto Acri
Alberto Acri 2022-12-16
编辑:Alberto Acri 2022-12-16
Thanks for the advice @Image Analyst. I posted a separate question about the "bwboundaries" function (link) because the function generates a curve (red) inside compared to the black curve (black pixels) shown in the image, while I would need the creation of the red curve inside (overlapping) the black curve (shown in the image). Once I understand this part I could use the functions you mentioned.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by