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

5 views (last 30 days)

Show older comments

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.

##### 0 Comments

### Accepted Answer

Image Analyst
on 12 Nov 2013

Edited: Image Analyst
on 12 Nov 2013

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 Comments

Image Analyst
on 15 Nov 2013

### More Answers (1)

Doug Hull
on 12 Nov 2013

### See Also

### Community Treasure Hunt

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

Start Hunting!