How to calculate median matrix of many .tif files with MATLAB?
7 ビュー (過去 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 で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!