cell配列中のすべての整数配列(画像)を含めたヒストグラムの出し方
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1770930/image.jpeg)
このcellに格納されているunit16配列のすべて(30個分)を含めた画素値のヒストグラムを作成したいと考えておりますが,どのようにすればよいのかが分かりません.
教えていただけると幸いです.
0 commentaires
Réponse acceptée
Kojiro Saito
le 12 Sep 2024
cell配列の要素ごとに処理するにはcellfun関数を使います。cropに格納されている画像サイズがまちまちなので、まずcellfunとimhistでヒストグラムを求めた後、ヒストグラムのカウントとビンの数を使ってstem関数で描く方法でいかがでしょうか。
下記の例はuint8の画像の例です。
img1 = imread('peppers.png');
img2 = imread('cameraman.tif');
crop = cell(1, 2);
crop{1} = img1;
crop{2} = img2;
% セル配列ごとに画像ヒストグラムを計算
[counts, binLocations] = cellfun(@imhist, crop, UniformOutput = false);
% 輝度値ごとのピクセル数を足し合わせ
tempVar = sum([counts{:}], 2);
% ヒストグラムを作成
stem(binLocations{1}, tempVar, Marker="none")
xlim([0 255]) % uint16なら[0 65535]とかにする
2 commentaires
Akira Agata
le 12 Sep 2024
+1
別のやり方として、いったんcell配列内の画素値をすべて一列に並べた数値配列を作成して、そのヒストグラムを描画するというやり方でも良いかと思います。以下はその一例です。
% サイズの異なるuint16配列を要素として持つセル配列の一例
img1 = randi(intmax("uint16"), 10, 20, "uint16");
img2 = randi(intmax("uint16"), 30, 40, "uint16");
crop = {img1, img2};
% 念のため確認してみる
crop
% すべての画素値を一列にならべた数値配列を作成
c = cellfun(@(x) x(:), crop', UniformOutput = false);
c = cell2mat(c);
% ヒストグラムを表示
figure
histogram(c)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Histograms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!