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 functionality. The 'Eccentricity', 'MajorAxisLength', 'MinorAxisLength' and 'Orientation' properties are my sticking point. In the documentation, they all derive from "...the ellipse that has the same second-moments as the region."
So my question is, what are these second-moments, and how do I find them?
I was looking at this link: http://en.wikipedia.org/wiki/Image_moments
Honestly, it's just left me more confused. Can anyone point me towards something a little more beginner friendly? Thanks.
The second moment of area is a measure of the 'efficiency' of a shape to resist bending caused by loading. A beam tends to change its shape when loaded. The second moment of area is a measure of a shape's resistance to change.
The first moment of area is the distribution of the area of a shape around a rotational axis. It is used to find the centroid of an area. The unit is in a cubic meter. The second moment of area or second area moment is the dispersion of points of a shape in an arbitrary axis.
In mathematics, the second moment method is a technique used in probability theory and analysis to show that a random variable has positive probability of being positive. More generally, the "moment method" consists of bounding the probability that a random variable fluctuates far from its mean, by using its moments.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With