이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
What is the best way to store groups of 3 nearest non-zero pixels?
조회 수: 1 (최근 30일)
이전 댓글 표시
Steve
2019년 9월 6일
![3_endpoint_sets_of_3_BW.bmp](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237233/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!
댓글 수: 1
채택된 답변
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
Steve
2019년 9월 6일
Thanks so much for your input. Looks great. I see you have the groups (sets of 3) all stored in one variable called "Groups". How do I get each set of 3 (x,y) coordinate pairs stored into their own variable (3 points per variable), so that I can call on them individually? Thanks again for your help!
Matt J
2019년 9월 6일
How do I get each set of 3 (x,y) coordinate pairs stored into their own variable (3 points per variable), so that I can call on them individually?
If you know there will always be 3 triplets, you can do
[T1,T2,T3]=deal(Triplets{:});
Steve
2019년 9월 6일
If they are stored in one variable, how do I call on each of the triplet sets individually?
Steve
2019년 9월 6일
Ok, cool. Last question (I hope)...How do I plot the triplets with index labels over the original image?
Matt J
2019년 9월 6일
I found some errors in the original code and edited it. The Triplets{i} are now returned as 2x3 matrices, but that is easy to change if it is not prefered.
Steve
2019년 9월 6일
MATLAB stopped and said "out of memory". Can I do this in a more efficient way? Thanks again for all your help.
Matt J
2019년 9월 6일
편집: Matt J
2019년 9월 6일
How do I plot the triplets with index labels over the original image?
In the meantime, I demonstrate below how to add labels to the triplets on your originally posted image with the attached plotpts2D.m file
C=cell2mat(cellfun(@(z)mean(z,2),Triplets,'uni',0) );
imshow(yourImage); hold on; plotpts2D(flipud(C)); hold off;
This will show,
![untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237255/untitled.png)
Steve
2019년 9월 6일
The only thing is when you zoom in to the plot, the index numbers pull away from the blue dots.
Matt J
2019년 9월 6일
Steven's comment moved here:
It's not that they re far from the points, it's more that they appear random (some are close, and some are far).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237264/image.png)
Matt J
2019년 9월 6일
편집: Matt J
2019년 9월 6일
it's more that they appear random (some are close, and some are far).
No, that's an illustion. The labels that appear to you to be close to a point really belong to a different point farther away. The distance between a point and its label is set uniformly in the code to the dd parameter in that line I showed you. It cannot vary from point to point.
Steve
2019년 9월 6일
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+
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)