opencv eigenfaces

Eigenfaces

The problem with the image representation we are given is its high dimensionality. Two-dimensional p \times q grayscale images span a m = pq-dimensional vector space, so an image with 100 \times 100 pixels lies in a 10,000-dimensional image space already. The question is: Are all dimensions equally useful for us? We can only make a decision if there’s any variance in data, so what we are looking for are the components that account for most of the information. The Principal Component Analysis (PCA) was independently proposed by Karl Pearson (1901) and Harold Hotelling (1933) to turn a set of possibly correlated variables into a smaller set of uncorrelated variables. The idea is, that a high-dimensional dataset is often described by correlated variables and therefore only a few meaningful dimensions account for most of the information. The PCA method finds the directions with the greatest variance in the data, called principal components.

Algorithmic Description

Let X = \{ x_{1}, x_{2}, \ldots, x_{n} \} be a random vector with observations x_i \in R^{d}.

  1. Compute the mean \mu

\mu = \frac{1}{n} \sum_{i=1}^{n} x_{i}

  1. Compute the the Covariance Matrix S

S = \frac{1}{n} \sum_{i=1}^{n} (x_{i} - \mu) (x_{i} - \mu)^{T}`

  1. Compute the eigenvalues \lambda_{i} and eigenvectors v_{i} of S

S v_{i} = \lambda_{i} v_{i}, i=1,2,\ldots,n

  1. Order the eigenvectors descending by their eigenvalue. The k principal components are the eigenvectors corresponding to the k largest eigenvalues.

The k principal components of the observed vector x are then given by:

y = W^{T} (x - \mu)

where W = (v_{1}, v_{2}, \ldots, v_{k}).

The reconstruction from the PCA basis is given by:

x = W y + \mu

where W = (v_{1}, v_{2}, \ldots, v_{k}).

The Eigenfaces method then performs face recognition by:

  • Projecting all training samples into the PCA subspace.
  • Projecting the query image into the PCA subspace.
  • Finding the nearest neighbor between the projected training images and the projected query image.

Still there’s one problem left to solve. Imagine we are given 400 images sized 100 \times 100 pixel. The Principal Component Analysis solves the covariance matrix S = X X^{T}, where {size}(X) = 10000 \times 400 in our example. You would end up with a 10000 \times 10000 matrix, roughly 0.8 GB. Solving this problem isn’t feasible, so we’ll need to apply a trick. From your linear algebra lessons you know that a M \times N matrix with M > N can only have N - 1 non-zero eigenvalues. So it’s possible to take the eigenvalue decomposition S = X^{T} X of size N \times Ninstead:

X^{T} X v_{i} = \lambda_{i} v{i}

and get the original eigenvectors of S = X X^{T} with a left multiplication of the data matrix:

X X^{T} (X v_{i}) = \lambda_{i} (X v_{i})

The resulting eigenvectors are orthogonal, to get orthonormal eigenvectors they need to be normalized to unit length. I don’t want to turn this into a publication, so please look into[Duda01] for the derivation and proof of the equations.

示例:

输入200张50x100图像,reshape成Mat(200,5000)
均值维度(1,5000)
特征值维度(min(n,200,5000),1)//n:配置的主成分个数
特征向量维度(min(n,200,5000),5000)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值