Relation between eigenvalues and size of geometrically shaped data in PCA

367 Views Asked by At

I want to measure the orientation and size of objects in a binary image using PCA. As I have a picture the data points are gridded (pixels). The object can be either an ellipse or a rectangle that I do not know beforehand. For the centered data points I calculate the eigenvalues and eigenvectors of the covariance matrix and then want to derive the object size from the eigenvalues. The problem is that the scaling of the eigenvalues depends on the shape of the data points.

Example

Let's assume I have an ellipse with full axes lengths (from one end to other end) $a=100,b=50$ and a rectangle with same dimensions. Both objects are rotated by $\theta=45$ deg. from the axis aligned state, see figure.

![enter image description here

The normalized eigenvectors direct as expected in the principal directions: $e_1\approx\dfrac{1}{\sqrt{2}} \begin{align} \begin{bmatrix}-1 \\ 1 \end{bmatrix}\end{align}$, $e_2\approx\dfrac{1}{\sqrt{2}} \begin{align} \begin{bmatrix}1 \\ 1 \end{bmatrix}\end{align}$. The corresponding eigenvalues $\lambda_1,\lambda_2$ are related to object sizes by $a=k \sqrt{\lambda_1},b=k \sqrt{\lambda_2}$. However $k$ depends on the shape. By testing many combinations of $a,b,\theta$ I can reproduce the dimensions of the ellipse if $k\approx4$ and for the rectangle if $k\approx2\sqrt{3}\approx3.46$. How can I derive $k$ from my original data as I do not know beforehand if my object is an ellipse or rectangle?

For completeness I give the covariance matrices of the depicted example:

ellipse (3927 data points): $\begin{align} \begin{bmatrix} 390.84770 & -234.51809 \\ -234.51809 & 390.84770 \end{bmatrix}\end{align}$

rectangle (4994 data points): $\begin{align} \begin{bmatrix} 518.98143 & -309.86476\\ -309.86476 & 518.98143 \end{bmatrix}\end{align}$

1

There are 1 best solutions below

3
On

It's not clear how one could obtain $k$ directly from the data, but here's a relatively simple way to obtain $a,b$. Given your principal components $e_1,e_2$, then it suffices to subtract the maximum and minimum components of the data in these directions.

That is, if $X$ is the matrix whose columns are the pixel coordinates, then $$ a = \max(e_1^TX) - \min(e_1^TX), \quad b = \max(e_2^TX) - \min(e_2^TX), $$ where for a vector $v$, $\max(v)$ denotes its maximum entry and $\min(v)$ denotes its minimum entry.