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

조회 수: 1 (최근 30일)
Steve
Steve 2019년 9월 6일
댓글: Steve 2019년 9월 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개)

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by