In the project I'm currently working on, I have to calculate 5 points of the image outline. For example, I can use to get a centroid. For this, I used matlab:
f = imread (Is);
%Edge detection with prewitt contourImage = edge(f,'prewitt'); % Morphological operation to close the open spaces se = strel('disk',2); closecontourImage = imclose(contourImage,se); imshow(closecontourImage); %Find the xy positions of all the nonzero elements of the edge [row,col] = find(closecontourImage); % 3 moments m10= 0; m00= 0; m01= 0; mu00 =0; % Calculate the 3 moments based on the given paper for r=1:length(row) for c=1:length(col) m10 = m10 + ((row(r)^1)*(col(c)^0)); m00 = m00 + ((row(r)^0)*(col(c)^0)); m01 = m01 + ((row(r)^0)*(col(c)^1)); end end % Calculate centroid (zwaartepunt) based on the given formulas x = m10/m00; y= m01/m00;
Original image (in png, I use pgm in matlab):

Edge (which I assume is the outline):

The plot with the image and the centroid 
When I compare this to matlabs built in centroid calculation, it is pretty close.
Although my problem is with calculating the area. I read that 0th moment = area. although my m00 does not match the area. This is logical because the 0th moment is the summation of all white pixels ... which represent only the edge of the image, so this cannot lead to this area. My question now is, is there a difference in the contour moments and moments in the whole image? And is it possible to get an area based on the outline in this view?
In my assignment, they clearly say that the moments of the contour must be calculated and that the first moment is equal to the centroid (which also does not correspond to my algorithm). But what I read here is that the central moment of the 1st order = centroid. Does this mean that the contour moments coincide with the central moments? And a more general question: can I use this edge as a path?
I find these points very confusing.
source share