What is the best way to store groups of 3 nearest non-zero pixels?

2 Ansichten (letzte 30 Tage)
Steve
Steve am 6 Sep. 2019
Kommentiert: Steve am 30 Sep. 2019
3_endpoint_sets_of_3_BW.bmp
I would like to identify and store each set of 3 closest points (as seen in the attached image) in a separate variable. So in this case, there would be three variables created--one for each set of three points. What would be the most efficient way to do this? Thanks in advance for your help!

Akzeptierte Antwort

Matt J
Matt J am 6 Sep. 2019
Bearbeitet: Matt J am 6 Sep. 2019
I would like to identify and store each set of 3 closest points (as seen in the attached image) in a separate variable.
No, you should not organize the result that way. What you should do is create a cell array called Triplets, such that Triplets{i} contains the points in the i-th triplet as a 2x3 matrix.
[I,J]=find(~yourImage);
X=[I,J];
[D,K]=pdist2(X,X,'euclidean','Smallest',3); X=X.';
K=unique( sort(K).', 'rows').'; K=K(:);
assert(numel(unique(K))==numel(K) ,'Points not well-separated enough for threshold' );
Triplets=num2cell( reshape( X(:,K), 2,3,[] ) ,[1,2]);
Triplets=Triplets(:).';
  25 Kommentare
Matt J
Matt J am 6 Sep. 2019
Glad it worked. Just Accept-click the answer and that will be thanks enough :-)
Steve
Steve am 30 Sep. 2019
Hi Matt,
I could really use your expertise again. I need to figure out how to modify your code in order to find the 10 nearest points to every other point within a group of points (i.e., 10 nearest neighrbors). The points I speak of are the Fermat center points to the Triplets we found in the previous task. I have found all these "Fermat points" and have their coordinates in the attached file (F_points.mat). As always, any help you could offer would be greatly appreciated.
Best
Steve

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by