How to calculate median matrix of many .tif files with MATLAB?
8 次查看(过去 30 天)
显示 更早的评论
Hi
I have for example 15 .tif files, some pixels with "NaN". How to find a matrix of the median of the 15 tif files
Is it possible?
to be more precice
The following link to subsample of the data:
input: 15 .tif files x m rows x n columns
output: so I want the out put be 1 median x m rows x n columns
Cheers
11 个评论
Walter Roberson
2023-11-2
If you have 120 files in the directory then how do you want to select the 15 of them you want to process?
采纳的回答
Walter Roberson
2023-11-2
format long g
master_size = [87, 207];
unzip Test.zip
files = dir('*.tif');
filenames = fullfile({files.folder},{files.name});
N = numel(files);
for ii = 1:N
files(ii).data = imresize(imread(filenames{ii}), master_size);
end
datablock = cat(3, files.data);
image_median = median(datablock, 3, 'omitnan');
[min(image_median(:)), max(image_median(:))]
image(image_median)
After that you want to write the median out to a tiff, and you probably want the same data range (rather than converting the image to uint8). imwrite() cannot itself write single precision tiff, so you need the Tiff library. More information is at https://www.mathworks.com/matlabcentral/answers/7184-how-can-i-write-32-bit-floating-point-tifs-with-nans . Or you could use the File Exchange contribution https://www.mathworks.com/matlabcentral/fileexchange/30519-export-image-to-tif-or-tiff-file-of-selected-data-type which you could install using the Add-On Explorer
4 个评论
Walter Roberson
2023-11-2
You might be interested in standardizeMissing
format long g
master_size = [87, 207];
unzip Test.zip
files = dir('*.tif');
filenames = fullfile({files.folder},{files.name});
N = numel(files);
for ii = 1:N
thisimg = imread(filenames{ii});
minval = min(thisimg(:));
if minval < -1e12
thisimg = standardizeMissing(thisimg, minval);
end
files(ii).data = imresize(thisimg, master_size);
end
datablock = cat(3, files.data);
image_median = median(datablock, 3, 'omitnan');
[min(image_median(:)), max(image_median(:))]
image(image_median)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Other Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!