Clustering coordinates on image

1 view (last 30 days)
jg
jg on 17 Apr 2020
Commented: jg on 19 Apr 2020
How would i cluster these points so that i am left wth 4 sets of coordinates in a 4 by 2 matrix currently it returns a 13 by 2.
This is the returned matrix.
centers =
16.5000 9.0000
8.5000 29.0000
423.0000 29.0000
18.5000 33.0000
30.0000 35.0000
448.5000 35.0000
431.5000 36.5000
37.5000 45.5000
456.5000 435.0000
43.5000 450.0000
426.5000 450.0000
445.0000 457.5000
439.5000 469.0000

Accepted Answer

Image Analyst
Image Analyst on 17 Apr 2020
Try this:
centers =[...
16.5000 9.0000
8.5000 29.0000
423.0000 29.0000
18.5000 33.0000
30.0000 35.0000
448.5000 35.0000
431.5000 36.5000
37.5000 45.5000
456.5000 435.0000
43.5000 450.0000
426.5000 450.0000
445.0000 457.5000
439.5000 469.0000];
subplot(1, 2, 1);
plot(centers(:, 2), centers(:, 1), 'r+', 'MarkerSize', 9, 'LineWidth', 2);
[indexes, centroids] = kmeans(centers, 4)
axis ij; % Flip axis direction.
grid on;
subplot(1, 2, 2);
gscatter(centers(:, 2), centers(:, 1), indexes);
axis ij; % Flip axis direction.
grid on;
% Put a big circle at the centroid
hold on;
plot(centroids(:, 2), centroids(:, 1), 'bo', 'MarkerSize', 30, 'LineWidth', 2);
You now have 4 clusters.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!