MATLAB Answers

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

1 view (last 30 days)
Steve
Steve on 6 Sep 2019
Commented: Steve on 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!

Accepted Answer

Matt J
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(:).';

  25 Comments

Steve
Steve on 6 Sep 2019
I set the parameter to: dd=diff(ylim)/2000; and it worked perfectly. You are amazing. What is the best way to officially rate your help and effort so you get the most credit?
For anyone reading this, Matt J is the best! A+
Matt J
Matt J on 6 Sep 2019
Glad it worked. Just Accept-click the answer and that will be thanks enough :-)
Steve
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

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2019a