How to get average image of a set of .bmp images?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, all
I am not stuck with a problem. I have a set of .bmp images, which are actually images of faces. I'd like to get the average image of these images. The following is what I do:
clear all
clc
path = 'C:\myImages\';
names = ls(path);
names(1:2,:)=[];
red = zeros(512, 512, 50);
green = zeros(512, 512, 50);
blue = zeros(512, 512, 50);
for i = 1:50
t = imread([path names(i,:)]);
red(:,:,1) = double(t(:,:,1));
green(:,:,2) = double(t(:,:,2));
blue(:,:,3) = double(t(:,:,3));
end
for i = 1:512
for j = 1:512
r(i,j) = mean(red(i,j,:));
g(i,j) = mean(green(i,j,:));
b(i,j) = mean(blue(i,j,:));
end
end
newimage(:,:,1) = uint8(r);
newimage(:,:,2) = uint8(g);
newimage(:,:,3) = uint8(b);
imshow(newimage)
You can see that I try to convert the uint8 pixel into double variables, find the average value of the pixels, then convert the variables back to uint8 type.
However, all I've got is a totally black image. I examine individual pixels of the new image, and the pixel valus are around 0~5.
May I know what is wrong with my code? Many thanks for your help!
Best regards Wenlong
0 Kommentare
Antworten (1)
Image Analyst
am 4 Mär. 2013
Why not just use the mean function:
meanRedImage = mean(red, 3);
meanGreenImage = mean(green, 3);
meanBlueImage = mean(blue, 3);
meanRGB = uint8(cat(3, meanRedImage, meanGreenImage, meanBlueImage));
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!