Loading multiple images, taking mean of them and subtracting background

3 vues (au cours des 30 derniers jours)
Sumera Yamin
Sumera Yamin le 13 Jan 2020
Modifié(e) : Meg Noah le 14 Jan 2020
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.

Réponses (1)

Meg Noah
Meg Noah le 14 Jan 2020
Modifié(e) : Meg Noah le 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

Catégories

En savoir plus sur Import, Export, and Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by