我试图找到灰度图像的特征值和向量并得到错误"矩阵维度必须同意"

时间:2016-04-07 08:03:01

标签: matlab

代码给出错误"矩阵维度必须同意"。那么我应该做些什么改变?

%reading a image
I =imread('C:\Program Files\MATLAB\R2013a\New folder\fac.jpg');

m = mean(I,2);

I = double(I)- double(repmat(m,10,1));

%calculating covariance matrix 
c=cov(I);

%calculating eigenvalues and eigenvectors
[eigenvalue,eigenvector]=eig(c);

1 个答案:

答案 0 :(得分:0)

首先,确保I是2D矩阵。这是cov工作所必需的。其次,使用repmat(m,n,p),其中npsize(repmat(m,n,p))==size(I)

示例

I =imread('myImg.jpg'); % 63x83x3 matrix containing 3D RGB information.
I = rgb2gray(I); % 3D RGB to 2D gray scale. Now I is a 63x83 matrix.
m = mean(I,2);                 
I = double(I)- double(repmat(m,1,83));  
c=cov(I);
[eigenvalue,eigenvector]=eig(c);