我正在为GNU Octave编写一个MATLAB RegionProps函数版本.我已经完成了大部分工作,但我仍然在努力实现一些部分.我之前曾询问过一个地区的第二个中心时刻.
这在理论上是有帮助的,但我实际上在实施这些建议时遇到了麻烦.我得到的结果与MATLAB(或者常识)的结果大不相同,真的不明白为什么.
考虑这个测试图像:

我们可以看到它与X轴成45度倾斜,次轴和长轴分别为30和100.
通过MATLAB的RegionProps功能运行它确认了这一点:
MajorAxisLength: 101.3362
MinorAxisLength: 32.2961
Eccentricity: 0.9479
Orientation: -44.9480
Run Code Online (Sandbox Code Playgroud)
与此同时,我甚至没有让轴正确.我正在尝试使用维基百科中的这些公式.
到目前为止我的代码是:
function outmom = raw_moments(im,i,j)
total = 0;
total = int32(total);
im = int32(im);
[height,width] = size(im);
for x = 1:width;
for y = 1:height;
amount = (x ** i) * (y ** j) * im(y,x);
total = total + amount;
end;
end;
outmom = total;
Run Code Online (Sandbox Code Playgroud)
function cmom = central_moments(im,p,q);
total …Run Code Online (Sandbox Code Playgroud)