필터 지우기
필터 지우기

Problem with creating .bmp images

조회 수: 3 (최근 30일)
Wenlong
Wenlong 2012년 9월 21일
Hi, all
I'm running PCA on ORL human face image database. What I want to achieve it to extract the principal components, then add the mean vector back to these component. By writing these components as .bmp images, I can get eigen faces. Here is my code
clc
clear all
close all
path = 'D:\\Matlab 7.0\\work\\ORL\\';
data = zeros(400, 10304);
for i = 1:400
name = [path 'face' num2str(i) '.bmp'];
temp = imread(name);
temp = reshape(temp, 1, 10304);
data(i, :) = temp;
end
meanface = mean(data, 1);
data = data - repmat(meanface, 400, 1);
intermat = (data * data') / (400-1);
[intervec, val] = eig(intermat);
pc = data'*intervec;
pc = pc';
for i = 1:400
pc(i,:) = pc(i,:) / sqrt(dot(pc(i,:), pc(i,:)));
sd(i) = sqrt(val(i,i));
eigenvalue(i) = val(i,i);
end
pc = flipud(pc);
sd = fliplr(sd);
eigenvalue = fliplr(eigenvalue);
%%%%%%Write images %%%%%%%
for i = 1:399
mode = pc(i,:) + meanface;
mode = round(mode);
mode = reshape(mode, 112, 92);
name = ['pc' num2str(i) '.bmp'];
imwrite(mode, name, 'bmp');
end
I was expecting to see ghost-like images. However, this piece of code writes images that all white.
May I know if there is anything wrong with my code?
Thank you very much for your kindly help.
Best regards Wenlong

답변 (1개)

Image Analyst
Image Analyst 2012년 9월 21일
I don't believe BMP supports floating point. If you want floating point, save as .mat. If you want a standard BMP, then cast to uint8 before saving, though beware that you may lose numerical resolution as it will truncate the values and may require scaling and shifting into the 0-255 value range.

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by