代码给出错误"矩阵维度必须同意"。那么我应该做些什么改变?
%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);
答案 0 :(得分:0)
首先,确保I
是2D矩阵。这是cov
工作所必需的。其次,使用repmat(m,n,p)
,其中n
和p
是size(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);