Max function working for a sample of images but not all

1 回表示 (過去 30 日間)
Sato Koyama
Sato Koyama 2019 年 9 月 13 日
コメント済み: Sato Koyama 2019 年 9 月 13 日
I have a multidimensional matrix and I want to find the position of the maximum.
So naturally, I used [~,idx]=max(M,[],num)
where M is the matrix thats mxnxa and num is the dimension a.
This worked for a specific sample of images that I'm testing but doesn't work for others.
The code looks like this.
%% variables
% images is a 1xa cell array with an image in each cell
% checkDistance is a mxnxa matrix that represents the distance from the median to an image.
% because i have 'a' images, checkDistance is 'a' dimensional.
dim=length(images);
[~, idx]=max(checkDistance,[],dim);
% idx should output a mxn matrix, not mxnxa
% doesn't really matter but this also applies to ~.
To reiterate, this ONLY works for a SPECIFIC sample of images. Could this be because of different filetypes? The sample that worked is .png and the one that didn't is .jpg...
EDIT1: made a set of samples that were jpg and worked. I'm starting to think there's an issue with the size of the image (1920x1280)
Any help is appreciated

採用された回答

Bruno Luong
Bruno Luong 2019 年 9 月 13 日
編集済み: Bruno Luong 2019 年 9 月 13 日
Sato's example code
[~,idx]=max(A,[],7)
No the correct call is
[~,idx]=max(A,[],3)
You take the max along the third dimension. The number of elements in the third dimension (7) or length of A does not play any role in the calling parameters of MAX (Just think how you call MAX for A = 7 x 7 x 7).
  1 件のコメント
Sato Koyama
Sato Koyama 2019 年 9 月 13 日
ohhh. okay i get it now. thank you so much.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 9 月 13 日
length(images) is defined as:
if isempty(images)
length <- 0
else
length <- max(size(images))
end
You can see that it is not any particular dimension of the array. It could even end up being the number of images instead of the number of rows or columns.
  1 件のコメント
Sato Koyama
Sato Koyama 2019 年 9 月 13 日
Say that I have a mxnx7 (call it A) matrix, and i want to find the maximum elements across the 7 layers.
wouldn't the idx from [~,idx]=max(A,[],7) output an mxn matrix because the dimension is 7, thus enough to interpret that the the maximum value is found across the 7 mxn matrices?
I'm not sure if I understand what you mean... because i made it so that length(images) outputs the dimension 'a'.

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by