Clear Filters
Clear Filters

cell内にある最大​値をもつ画像を取り出​す方法について

8 views (last 30 days)
KT
KT on 2 May 2023
Commented: KT on 5 May 2023
ある画像に対し,最大値を検出し,その行列を求めることは,
A = [1 2; 3 4]; % 行列
maximum = max(max(A));
[x,y]=find(A==maximum)
で可能ですが,
cell内にいくつかの画像がある場合には,
cell2mat(A);
max(A(:));
にてcellを行列に分解して最大値を取り出すことはできますが,その最大値が含まれた画像を取り出す場合はどうのようにすればいいのでしょうか.
ご教示のほどよろしくお願い申し上げます.

Accepted Answer

交感神経優位なあかべぇ
Edited: 交感神経優位なあかべぇ on 3 May 2023
画像はグレースケール、また、セル配列内の画像の解像度はそれぞれ異なる場合の最大値を含む画像を取り出すサンプルコードを記述します。
% サンプル画像の作成(10個の画像群のうち、3番目と7番目に適当に最大値となる値を仕込む)
testImg = arrayfun(@(x) randi([0,254], 5+x, 5+x, 'uint8'), 1 : 10, 'UniformOutput',false);
testImg{3}(end) = 0xFF;
testImg{7}(30) = 0xFF;
% 2次元配列のデータを1次元配列に変換
imgLinear = cellfun(@(x) x(:), testImg, 'UniformOutput', false);
% セル配列を1次元配列のデータに変換
imgLinearData = vertcat(imgLinear{:}); % 左の{:}は、vertcat(imgLinear{1}, imgLinear{2}, ..., imgLinear{end}) と同義
% 最大値の算出
maxVal = max(imgLinearData);
% 最大値のデータを持つ画像の判定(3番目と7番目がTrueになっていれば正解)
imgIncludeMaxIdx = cellfun(@(x) any(x==maxVal, 'all'), testImg)
imgIncludeMaxIdx = 1×10 logical array
0 0 1 0 0 0 1 0 0 0
% 元画像群から、最大値を持つ画像だけを取り出す。
imgIncludeMaxData = testImg(imgIncludeMaxIdx);
  1 Comment
KT
KT on 5 May 2023
返信が遅れて大変申し訳ありません.
cell行列を1次元配列にする→再度画像に戻すことができませんでした.
cellfunの使い方を勉強いたします.
ご教示頂きありがとうございました.

Sign in to comment.

More Answers (0)

Categories

Find more on イメージ in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!