Oli*_*s_j 4 matlab image-processing
在我正在研究的项目中,我必须计算图像轮廓的5个矩.然后我可以使用它来获得质心.为此,我使用了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 x y 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;
Run Code Online (Sandbox Code Playgroud)
原始图像(在png中,我在matlab中使用pgm):

边缘(我假设是轮廓):

带有图像和质心的情节

当我把它与质心计算中建立的matlabs进行比较时,它非常接近.
虽然我的问题是关于面积计算.我读到第0个时刻=区域.虽然我的m00与该地区不一样.这是合乎逻辑的,因为第0个时刻是所有白色像素的总和......它们仅代表图像的边缘,因此这不会导致该区域.我现在的问题是,整个图像上的轮廓力矩和力矩是否存在差异?是否可以根据此表示中的轮廓获得区域?
在我的作业中,他们明确地说应该计算轮廓的矩,并且1ste矩等于质心(在我的算法中也不是这种情况).但我在这里读到的是第一阶中心力矩=质心.那么这是否意味着轮廓力矩与中心力矩相同?还有一个更普遍的问题,我可以将这个边缘用作轮廓吗?
我发现这些时刻非常令人困惑