フィルターのクリア

Getting the maximum value of several matrices loaded from image files.

2 ビュー (過去 30 日間)
Chiara
Chiara 2013 年 11 月 12 日
コメント済み: Image Analyst 2013 年 11 月 15 日
I have troubles with the max command applied to images files.
I have N=108 image files tif. Each file corresponds to a matrix. I need to load all the matrix/images and compute a matrix containing the maximum values among the 108 matrices.
My script to read the N=108 files is as follows:
imagelist = dir('*.tif');
N = numel(imagelist);
imdata = cell(1, numel(imagelist));
for k = 1: N
imdata{k} = imread(imagelist(k).name);
end
I don’t know to compute the “maximum matrix” since imdata contains matrices as cells.
Using
M=max(imdata{k})
indeed I obtain a row vector containing only the maximum values of the first cell.

採用された回答

Image Analyst
Image Analyst 2013 年 11 月 12 日
編集済み: Image Analyst 2013 年 11 月 12 日
Something like this (untested):
maxImage = zeros(rows, columns, 'uint8');
overallMax = -inf;
for k = 1: N
thisImage = imread(imagelist(k).name);
% Get max of this image.
thisMax = max(thisImage(:));
if thisMax > overallMax
overallMax = thisMax;
end
% Get max image, in case you really meant that. Delete if not.
maxImage = max(maxImage, thisImage);
end
Of course you need to make sure that the dimensions (rows, columns, number of color channels) of all the images match up.
  4 件のコメント
Chiara
Chiara 2013 年 11 月 15 日
The error refers to "uint8" command. I correct in order to have all values with the same precision (single). Now it perfectly works. I meant to have the max image though. Thank you a lot
Image Analyst
Image Analyst 2013 年 11 月 15 日
OK good. MATLAB has a rule that integers must be combined with integers of the same class. Usually that comes into play when you're adding or multiplying them but I guess you found out that it also applies when you use the max function. There's no such rule for floating point numbers. Anyway, I'm glad you got it working and accepted the answer.

サインインしてコメントする。

その他の回答 (1 件)

Doug Hull
Doug Hull 2013 年 11 月 12 日
Do not store the images in cells. Just load each in turn, get the maximum value. Compare this maximum value to the previously found maximum value. Keep the maximum of those two. Repeat until all have been done.
  1 件のコメント
Chiara
Chiara 2013 年 11 月 13 日
Thanks for your answer. I cannot convert the cells into matrices though. I’ve tried to automatically upload the 108 tif files I have, using strcat function but doesn’t work. My files are “200301_monthly_adg_443_gsm_P90.tif” The only part varying is the first “200301”. I have already implemented strcat function but not with images.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by