What are the second-moments of a region?

后端 未结 3 1223
既然无缘
既然无缘 2020-12-14 12:29

I\'m currently working on replicating some of the functionality of Matlab\'s regionprops function in Octave. However, I have a bit of a hangup on a subset of the functional

相关标签:
3条回答
  • 2020-12-14 12:37

    By "second moments", the documentation means the second central moment.

    In the case of one-dimensional data, this would be the variance (or square of the standard deviation).

    In your case, where you have two-dimensional data, the second central moment is the covariance matrix.

    If X is an n-by-2 matrix of the points in your region, you can compute the covariance matrix Sigma in MATLAB like this (untested):

    mu=mean(X,1);
    X_minus_mu=X-repmat(mu, size(X,1), 1);
    Sigma=(X_minus_mu'*X_minus_mu)/size(X,1);
    

    Now, what does this have to do with ellipses? Well, what you're doing here is, in effect, fitting a multivariate normal distribution to your data. The covariance matrix determines the shape of that distribution, and the contour lines of a multivariate normal distribution -- wait for it -- are ellipses!

    The directions and lengths of the ellipse's axes are given by the eigenvectors and eigenvalues of the covariance matrix:

    [V, D]=eig(Sigma);
    

    The columns of V are now the eigenvectors (i.e. the directions of the axes), and values on the diagonal of D are the eigenvalues (i.e. the lengths of the axes). So you already have the 'MajorAxisLength' and 'MinorAxisLength'. The orientation is probably just the angle between the major axis and the horizontal (hint: use atan2 to compute this from the vector pointing along the major axis). Finally, the eccentricity is

    sqrt(1-(b/a)^2)
    

    where a is the length of the major axis and b is the length of the minor axis.

    0 讨论(0)
  • 2020-12-14 12:58

    I'm not exactly sure, but doesn't this refer to the statistical notion of moments (as in moment generating function):

    Central Moments (moments about the mean):
       mu_k = E[(X − E[X])^k] ,    where E is the expected value

    Thus the first four moments are respectively: {1, variance, skewness, kurtosis}.
    But again I might be wrong ;)

    0 讨论(0)
  • 2020-12-14 13:02

    Not exactly the answer you seek, but it might help someone.

    I wrote this book on the subject of mechanics and wrote m-files to calculate the area moment of inertia:

    Mastering Mechanics using MATLAB 5

    The code from it can be found here:

    File Exchange

    Chapter 9 should be of interest. I suspect you could use the code as a starting point.

    0 讨论(0)
提交回复
热议问题