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

4 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Image Analyst
Image Analyst il 13 Dic 2022
Modificato: Image Analyst il 13 Dic 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 Commenti
Image Analyst
Image Analyst il 15 Dic 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 il 16 Dic 2022
Modificato: Alberto Acri il 16 Dic 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.

Accedi per commentare.

Categorie

Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by