Loading multiple images, taking mean of them and subtracting background

3 visualizaciones (últimos 30 días)
Sumera Yamin
Sumera Yamin el 13 de En. de 2020
Editada: Meg Noah el 14 de En. de 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.

Respuestas (1)

Meg Noah
Meg Noah el 14 de En. de 2020
Editada: Meg Noah el 14 de En. de 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

Categorías

Más información sobre Import, Export, and Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by