필터 지우기
필터 지우기

How to calculate the centroid / center of a patch?

조회 수: 8 (최근 30일)
Sim
Sim 2022년 3월 1일
편집: Sim 2022년 3월 1일
Hi, how can I calculate the centroid / center of a patch?
Maybe something like this?
[Xc,Yc] = centroid(patch('XData',X,'YData',Y))
  댓글 수: 2
jessupj
jessupj 2022년 3월 1일
i have you tried polyshape instead of a patch? you're defining the patch there with x,y data, so you can use those data to define the right object to apply centroid to
Sim
Sim 2022년 3월 1일
Thanks a lot @jessupj ! Indeed, @David Hill showed (I think at the same time with you) this solution :)

댓글을 달려면 로그인하십시오.

채택된 답변

David Hill
David Hill 2022년 3월 1일
pgon=polyshape(X,Y);
[x,y]=centroid(pgon);

추가 답변 (2개)

Constantino Carlos Reyes-Aldasoro
The data X,Y must have been previously calculated from some raw data, say a thresholded figure, it is from that data you can easily calculate centroids with regionprops
  댓글 수: 1
Sim
Sim 2022년 3월 1일
Thanks a lot @Constantino Carlos Reyes-Aldasoro, very kind!
(however I accepted the @David Hill solution since showing an example of code)

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2022년 3월 1일
Depends on what you have. If you have just arbitrary (x,y) data gotten somehow, like through assignment, then you can create a polyshape with the polyshape() function, and then use centroid(), like @David Hill showed.
If you have a binary image (like @Constantino Carlos Reyes-Aldasoro assumed -- say from thresholding), and want the centroid of each region, you can use regionprops():
props = regionprops(binaryImage, 'Centroid');
xyCentroids = vertcat(props.Centroid)
If you'd like a tutorial on image segmentation that shows that, you can see my Image Segmentation Tutorial:
  댓글 수: 1
Sim
Sim 2022년 3월 1일
편집: Sim 2022년 3월 1일
Yes, very true, it depends on what you have!
Yes, both replies from @David Hill, @Constantino Carlos Reyes-Aldasoro and @jessupj are very good, and it just depends on what data / scenario you have....
Thanks a lot for the Tutorial! Seems very interesting! I guess this one:

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by