cell配列に格納されているクラス名によって色を変えて画像を表示するにはどうすればよいですか?
Afficher commentaires plus anciens
predicted_imageは、読み込んだ画像の各ピクセルごとに機械学習で判定したクラス名が格納されてる512×512 cell配列です。
クラス名ごとに色を変えて表示したいのですが、どのように行えばよいでしょうか?
例えば、犬として判定されたピクセルを赤色、猫として判定されたピクセルを青色として凡例とともに表示したいです。

% 予測結果を画像データに変換する。
predicted_image = reshape(yfit, size_array(1), size_array(2));
% セル配列内のユニークなクラス名を取得
unique_classes = unique(yfit);
% クラスの数を計算
num_classes = numel(unique_classes);
% クラスごとの色を生成
class_colors = jet(num_classes); % 例としてJet colormapを使用
% クラスごとに色を変えて画像として表示
Réponse acceptée
Plus de réponses (1)
%colors
r = [1 0 0];
b = [0 0 1];
%Random data
in = {'inu', 'neko'};
idx = randi(2,512,512);
in = in(idx);
%% If the data inside cell array is charactar array, use strcmp()
%here I have taken the data to be character array
out=strcmp(in,'inu');
%% If the data inside cell array is categorical array, use ==
%out = in==categorical('inu');
%red for inu, blue for neko
%1x1x3 for colored image
img = out.*reshape(r,1,1,3)+(~out.*reshape(b,1,1,3));
image(img)
Adding legends corresponding to a image is not possible. The workaround is to plot NaN data and use them as legend -
hold on
scatter(nan,nan,[],r,'.','DisplayName','inu')
scatter(nan,nan,[],b,'.','DisplayName','neko')
hold off
legend
1 commentaire
Natsuo OKADA
le 21 Oct 2023
Catégories
En savoir plus sur 測定と特性抽出 dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


