Loading multiple images, taking mean of them and subtracting background
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Meg Noah
2020-1-14
编辑:Meg Noah
2020-1-14
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Biomedical Imaging 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!