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

2 次查看(过去 30 天)
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!

采纳的回答

Matt J
Matt J 2019-9-6
编辑:Matt J 2019-9-6
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 个评论
Matt J
Matt J 2019-9-6
Glad it worked. Just Accept-click the answer and that will be thanks enough :-)
Steve
Steve 2019-9-30
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by