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

1 view (last 30 days)
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.

Answers (1)

Image Analyst
Image Analyst on 13 Dec 2022
Edited: Image Analyst on 13 Dec 2022
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 Comments
Image Analyst
Image Analyst on 15 Dec 2022
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 on 16 Dec 2022
Edited: Alberto Acri on 16 Dec 2022
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.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!