Four coordinates of a rectangle are given. I need to find the centroid of the area enclosed by the polygon.
Either provide the pixel values and coordinate values of all the pixels enclosed by the polygon OR Provide the centroid of the polygon directly. Please help me out.

 채택된 답변

Image Analyst
Image Analyst 2016년 7월 29일

1 개 추천

You don't need MATLAB for that, but if you insist. Assuming the x coordinates and y coordinates are in separate arrays....
xCentroid = mean(x);
yCentroid = mean(y);
If you want a digital image pixel value, then round to the nearest row and column:
grayLevel = grayImage(round(yCentroid), round(xCentroid));

댓글 수: 3

Bankim Chandra Yadav
Bankim Chandra Yadav 2016년 7월 29일
편집: Bankim Chandra Yadav 2016년 7월 29일
I have any four points on the image. I know the intrinsic coordinates of the points. What i need is to know the intensity weighted centroid of the area covered inside the polygon enclosed by the four points. The calculation needs the gray values of each pixel enclosed and their coordinates.
Please look at the image attatched.
PS. I respect your status, Image Analyst on Matlab Answers™.
Image Analyst
Image Analyst 2016년 7월 29일
In MATLAB, that's called the weighted centroid - like a center of mass. That is weighted by the pixel values. The plain centroid is just based on the shape alone (of the binary image) and doesn't care at all about pixel values. To compute the centroid of weighted centroid, get a binary image, for example using poly2mask()), then call regionprops. Attached is a demo. If it answers your question, you can "Accept this answer" and vote for it.
Accepted.

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

추가 답변 (0개)

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by