Loading multiple images, taking mean of them and subtracting background

4 views (last 30 days)
Hi,
I am new to the field of image analysis. my problem is that i want to load multiple images (lets say 20), take the mean of all these images to produce one image, and then subtract a background image from this mean image. Any help will be highly appreciated.

Answers (1)

Meg Noah
Meg Noah on 14 Jan 2020
Edited: Meg Noah on 14 Jan 2020
change the .png for whatever file extension you are using. Are your image greyscale? If not, it might not make sense to background mean subtract different color channels of data.
myDir = '';
fileList = dir(fullfile(myDir,'*.png'));
nfiles = length(fileList);
totalValuePerImage = zeros(nfiles,1);
nPixelsPerImage = zeros(nfiles,1);
for ifile = 1:length(fileList)
I = imread(fullfile(myDir,fileList(ifile).name));
totalValuePerImage(ifile) = sum(I(:));
nPixelsPerImage = double(numel(I));
end
globalMean = sum(totalValuePerImage)/sum(nPixelsPerImage);
for ifile = 1:length(fileList)
I = imread(fullfile(myDir,fileList(ifile).name));
[~,fileLeaf,~] = fileparts(fileList(ifile).name);
I = double(I) - globalMean;
save([fileLeaf '.mat'],'I');
end

Categories

Find more on Biomedical Imaging 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!