Loading multiple images, taking mean of them and subtracting background

3 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Meg Noah
Meg Noah il 14 Gen 2020
Modificato: Meg Noah il 14 Gen 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

Categorie

Scopri di più su Biomedical Imaging in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by