average image intensity problem
Show older comments
Hello, I want to average the intensity of 10 images, but the result whole image is white.
clc;clear all; close all;
% Specify the folder where the files live.
myFolder = 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.bmp'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray{k} = imread(fullFileName);
imshow(imageArray{k}); % Display image.
drawnow; % Force display to update immediately.
end
[Resolution_Y, Resolution_X] = size(imageArray{1});
ReferenceImag = zeros(k,Resolution_Y,Resolution_X);
ReferenceImag(1,:,:)= double( imageArray{1} );
for j=2:k
%ReferenceImag(1,:,:)= double( imageArray{1} );
ReferenceImag(j,:,:)= squeeze(ReferenceImag(j-1,:,:))+ double( imageArray{j} );
end
ReferenceImag = ReferenceImag./k;
ReferenceImag = round(ReferenceImag,0);
newReferenceImag = squeeze(ReferenceImag(k,:,:));
imshow(mat2cell(newReferenceImag));
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!