Batch processing images to average pixel values- blank output

조회 수: 1 (최근 30일)
Shant
Shant 2014년 10월 29일
댓글: Shant 2014년 10월 29일
After much help from the community on here, and some minor tweaking I finally have a code for batch processing images for an averaged image. It seems like the entire code is functioning properly except for the final output. The output should be an average of all images in the folder selected, however it is outputting a blank white image rather than an averaged image. I have checked the arrays, and the arrays hold proper averaged pixel values for the batch of images. Which leads me to my question.... Why won't this code output a proper averaged image?
clc;
clear all;
close all;
% User selecting image directory
cd(uigetdir);
% Counting number of .JPG's in folder
Files = dir('*.jpg');
b=numel(Files);
% Initialize to first image.
I0 = imread('IMG_1.jpg')
sumImage = double(I0);
% Read in remaining images.
for i=2:b
rgbImage = imread(['IMG_',num2str(i),'.jpg']);
sumImage = sumImage + double(rgbImage);
end;
% Average Image and output file
meanImage = sumImage / b
imshow(meanImage);
imshow(meanImage,'Border','Tight');
set(gcf, 'PaperPositionMode', 'auto');
h = gcf;
saveas(h, [cd '\' 'IMG_Average'], 'jpg');
As you can see in the following picture, the array shows pixel values, but the figure is blank

채택된 답변

Image Analyst
Image Analyst 2014년 10월 29일
meanImage needs to be uint8:
meanImage = uint8(sumImage / b);

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by