特征脸显示不正确并且很暗
我需要使用 PCA 显示图像特征向量矩阵的前 10 个特征脸。
我正在使用以下 matlab 代码来创建第一个特征脸,但我变得很暗并且特征脸不太正确。 eFea 是一个 240x4096 的矩阵,其中每行代表 64x64 的图像,
newData = eFea';
data = newData;
[M,N] = size(data);
mn = mean(data,2);
data = double(data) - repmat(mn,1,N);
% construct the matrix Y
Y = data' / sqrt(N-1);
% SVD
[u,S,PC] = svd(Y,0);
imshow(reshape(PC(1,:),64,64))
任何有关代码错误的提示都会有所帮助。
I need to show 1st 10 eigenfaces using PCA for a image feature vector matrix.
I am using following matlab code to create 1st eigenface but I am getting very dark and not so correct eigenfaces.
eFea is a matrix of 240x4096 where each row represents an image of 64x64
newData = eFea';
data = newData;
[M,N] = size(data);
mn = mean(data,2);
data = double(data) - repmat(mn,1,N);
% construct the matrix Y
Y = data' / sqrt(N-1);
% SVD
[u,S,PC] = svd(Y,0);
imshow(reshape(PC(1,:),64,64))
any hints regarding the error in code will be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IMSHOW 不会自动缩放图像。因此,如果特征脸中只有 0 到 0.3 的值,那么一切都会非常黑暗。尝试使用
imshow(reshape(PC(1,:),64,64),[])
代替。IMSHOW does not automatically scale the image. Thus, if you only have values from, say, 0 to 0.3 in the eigenface, everything will be really dark. Try
imshow(reshape(PC(1,:),64,64),[])
instead.这是一个非常古老的话题,但我还是想回答一些问题。
老实说,我认为错误在其他地方,尽管乔纳斯所说的可能会给出不错的结果。
最后需要再次添加数据的平均值。我只是对深色主成分有同样的问题,这就是我发现这个问题的原因。但后来我意识到,当你进行 PCA 时,你首先减去平均值。这意味着最后你需要再次添加它。
This is a really old topic but I want to answer something anyway.
Honestly, I think the error is somewhere else, although what Jonas said might give good-looking results.
You need to add the mean of the data again in the end. I just had the same problem with the dark principal components, that's why I found this question. But then I realized, that when you do PCA, you substract the mean first. That means that in the end, you need to add it again.