how to merge centroids?
Show older comments
how can i merge centroid on top right corner?
if the centroids of any pair are closer than a certain amount

3 Comments
Benjamin Thompson
on 25 May 2022
Posting a raw image and your code for getting centroids out of that image can help the Community provide a good answer more quickly.
In general, you can make use of a property of subtraction in MATLAB to quickly calculate the differences between all combinations of numbers in a set:
» X = rand(1,5)
X =
0.655740699156587 0.035711678574190 0.849129305868777 0.933993247757551 0.678735154857773
» Y = rand(1,5)
Y =
0.757740130578333 0.743132468124916 0.392227019534168 0.655477890177557 0.171186687811562
» X - X'
ans =
0 -0.620029020582397 0.193388606712190 0.278252548600964 0.022994455701187
0.620029020582397 0 0.813417627294588 0.898281569183361 0.643023476283584
-0.193388606712190 -0.813417627294588 0 0.084863941888773 -0.170394151011004
-0.278252548600964 -0.898281569183361 -0.084863941888773 0 -0.255258092899777
-0.022994455701187 -0.643023476283584 0.170394151011004 0.255258092899777 0
» dX_values = X - X'
dX_values =
0 -0.620029020582397 0.193388606712190 0.278252548600964 0.022994455701187
0.620029020582397 0 0.813417627294588 0.898281569183361 0.643023476283584
-0.193388606712190 -0.813417627294588 0 0.084863941888773 -0.170394151011004
-0.278252548600964 -0.898281569183361 -0.084863941888773 0 -0.255258092899777
-0.022994455701187 -0.643023476283584 0.170394151011004 0.255258092899777 0
» dY_values = Y - Y'
dY_values =
0 -0.014607662453417 -0.365513111044165 -0.102262240400777 -0.586553442766772
0.014607662453417 0 -0.350905448590748 -0.087654577947360 -0.571945780313354
0.365513111044165 0.350905448590748 0 0.263250870643388 -0.221040331722606
0.102262240400777 0.087654577947360 -0.263250870643388 0 -0.484291202365995
0.586553442766772 0.571945780313354 0.221040331722606 0.484291202365995 0
» distances = sqrt(dX_values.^2 + dY_values.^2)
distances =
0 0.620201072368244 0.413520238381710 0.296449062428468 0.587003991651289
0.620201072368244 0 0.885879715449129 0.902548116484463 0.860581876796204
0.413520238381710 0.885879715449129 0 0.276591593378040 0.279093165353078
0.296449062428468 0.902548116484463 0.276591593378040 0 0.547443752982836
0.587003991651289 0.860581876796204 0.279093165353078 0.547443752982836 0
Keane Athallah
on 26 May 2022
Keane Athallah
on 26 May 2022
Answers (1)
Categories
Find more on Image Segmentation 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!