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

1 view (last 30 days)
Steve on 6 Sep 2019
Commented: Steve on 30 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. 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!
Walter Roberson on 6 Sep 2019
image appears to be blank??

Matt J on 6 Sep 2019
Edited: Matt J on 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(:).';
Steve on 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

R2019a

### Community Treasure Hunt

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

Start Hunting!