0以外の値を平均したいです
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
宗樹 岡本
am 5 Dez. 2023
Kommentiert: 宗樹 岡本
am 5 Dez. 2023
画像のRGB値からR値、G値、B値(それぞれ0以外の値)の平均値を算出したいです。ご教授よろしくお願いいたします。
下記のプログラムでは0も含んだ平均値となってしまいます
I = imread("");
R = double(I(:,:,1));
G = double(I(:,:,2));
B = double(I(:,:,3));
Rmean = mean2(R);
Gmean = mean2(G);
Bmean = mean2(B);
0 Kommentare
Akzeptierte Antwort
Kenjiro Sugimoto
am 5 Dez. 2023
こちらでいかがでしょうか。
R = [ 1, 0, 0; 0, 1, 0; 0, 0, 1 ];
Rmean = mean(R, "all")
idx = (R ~= 0) % 非ゼロの箇所を取得
Rmean = mean(R(idx), "all")
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu イメージ算術 finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!