0以外の値を平均したいです

13 vues (au cours des 30 derniers jours)
宗樹 岡本
宗樹 岡本 le 5 Déc 2023
Commenté : 宗樹 岡本 le 5 Déc 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);

Réponse acceptée

Kenjiro Sugimoto
Kenjiro Sugimoto le 5 Déc 2023
こちらでいかがでしょうか。
R = [ 1, 0, 0; 0, 1, 0; 0, 0, 1 ];
Rmean = mean(R, "all")
Rmean = 0.3333
idx = (R ~= 0) % 非ゼロの箇所を取得
idx = 3×3 logical array
1 0 0 0 1 0 0 0 1
Rmean = mean(R(idx), "all")
Rmean = 1
  1 commentaire
宗樹 岡本
宗樹 岡本 le 5 Déc 2023
ありがとうございました。

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!