How to write a .bmp format file?

Hi, all
I am using Principal Component Analysis (PCA) to analyze a 2D facial image database (ORL database). Here is my code
-----------------------------------------
data = zeros(400, 10304);
for i = 1:400
name = ['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);
---------------------------------------
After PCA, I try to write an eigenface in a .bmp image
face = meanface + sd(1) * pc(1,:);
face = reshape(face, 112, 92);
imwrite(face, 'eigenface.bmp');
However, what I get is a pure white image. Then I try to write meanface alone, and the result is all the same, a white plane. Till I try to write a principal component alone, the contour of a human face reveals.
Can anyone help me to find my mistake?
Many thanks in advance.
Sincerely Wenlong

1 Kommentar

Jan
Jan am 31 Aug. 2012
While the PCA part of the code is not relevant for the actual problem, it would be more helpful if you explain 1. the range and type of the variable "face" and 2. how you determine that the image is white.
Perhaps there is a confusion with UINT8 and DOUBLE types of the image? Or the re-import fails.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 31 Aug. 2012

0 Stimmen

Try this:
face_uint8 = uint8(255 * mat2gray(face));
fullFileName = fullfile(folder, 'eigenface.bmp'); % Or call uiputfile() if you want.
imwrite(face_uint8, fullFileName);

Kategorien

Gefragt:

am 31 Aug. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by