필터 지우기
필터 지우기

How to get average image of a set of .bmp images?

조회 수: 2 (최근 30일)
Wenlong
Wenlong 2013년 3월 4일
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

답변 (1개)

Image Analyst
Image Analyst 2013년 3월 4일
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));

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by